﻿//////////////////////////////////////////////////////////////////////////
//																		
//	这里的实现是Acad17版本适用的代码，其他版本如实现有不同需要重写！	
//	如StartAcad,GetColor等函数，用到了版本特定的Guid，必须重写。			
//
//	#ifndef OVERWRITE_FUNCTION_XXX
//	void XXX()
//	{...}
//	#endif
//	对应的CPP里定义OVERWRITE_FUNCTION_XXX，并重写函数
//																		
//////////////////////////////////////////////////////////////////////////

#pragma region include

#include "StdAfx.h"

#include <math.h>

#include "ExportToACADDlg.h"
#include "ExportProgressDlg.h"
#include "hc.h"
#include "HUtilityAnnotation.h"
#include "HGlobals.h"

#include "../ModelObj/System.h"
#include "../ModelObj/Layer.h"
#include "../ModelObj/ModelObjOption.h"
#include "../ModelObj/IModelObjEvent.h"
#include "../ModelObj/SubSystem.h"
#include "../ModelObj/Device.h"
#include "../ModelObj/Connector.h"
#include "../ModelObj/Pin.h"
#include "../ModelObj/Cable.h"
#include "../ModelObj/SubCable.h"
#include "../ModelObj/Wire.h"
#include "../ModelObj/SystemDisplayObj.h"
#include "../ModelObj/DeviceDisplayObj.h"
#include "../ModelObj/ConnectorDisplayObj.h"
#include "../ModelObj/PinDisplayObj.h"
#include "../ModelObj/WireDisplayObj.h"
#include "../ModelObj/TextDisplayObj.h"
#include "../ModelObj/ImageProp.h"
#include "../ModelObj/BackgroundDisplayObj.h"
#include "../ModelObj/Transform.h"
#include "../ModelObj/Vec.h"
#include "../ModelObj/Subline.h"
#include "../ModelObj/SublineDisplayObj.h"
#include "../ModelObj/TextNoteObj.h"
#include "../ModelObj/SchematicBus.h"
#include "../ModelObj/SchematicBusEntry.h"
#include "../ModelObj/SchematicConnectivty.h"
#include "../ModelObj/SubCableDisplayObj.h"
// #include "../ModelObj/Shape.h"
// #include "../ModelObj/ShapeDisplayObj.h"
#include "../ModelObj/LineDisplayObj.h"
#include "../ModelObj/EllipsDisplayObj.h"
#include "../ModelObj/RectangleDisplayObj.h"
#include "../ModelObj/RoundRectangleDisplayObj.h"
#include "../ModelObj/PolygonDisplayObj.h"
#include "../ModelObj/ImageDisplayObj.h"
#include "../ModelObj/ImageObj.h"
#include "../ModelObj/GroundUnit.h"
#include "../ModelObj/GroundUnitDisObj.h"
#include "../ModelObj/Ground.h"
#include "../ModelObj/GroundDisplayObj.h"
#include "../ModelObj/DisplayObj.h"
#include "../ModelObj/PageSetup.h"
#include "../ModelObj/BasePageSetup.h"
#include "../ModelObj/PageTemplateSetup.h"
#include "../ModelObj/GroundPatternDisObj.h"
#include "../ModelObj/GroundPatternObj.h"
#include "../ModelObj/SubCableTying.h"
#include "../ModelObj/SubCableTyingDisObj.h"

#include "../InterfaceCircuit/ICircuit.h"
#include "../InterfaceCircuit/CircuitUnit.h"
#include "../InterfaceCircuit/CircuitWire.h"
#include "../InterfaceCircuit/CircuitBus.h"
#include "../InterfaceCircuit/CircuitPart.h"
#include "../InterfaceCircuit/CircuitLine.h"
#include "../InterfaceCircuit/CircuitPolyline.h"
#include "../InterfaceCircuit/CircuitPolygon.h"
#include "../InterfaceCircuit/CircuitRectangle.h"
#include "../InterfaceCircuit/CircuitArc.h"
#include "../InterfaceCircuit/CircuitPin.h"
#include "../InterfaceCircuit/CircuitEllipse.h"
#include "../InterfaceCircuit/CircuitEllipseArc.h"
#include "../InterfaceCircuit/CircuitAnnotation.h"
#include "../InterfaceCircuit/ICircuitDisObj.h"
#include "../InterfaceCircuit/CircuitUnitDisObj.h"
#include "../InterfaceCircuit/CircuitFont.h"
#include "../InterfaceCircuit/CircuitPowerPort.h"
#include "../InterfaceCircuit/CircuitBusEntry.h"
#include "../InterfaceCircuit/CircuitJunction.h"
#include "../InterfaceCircuit/CircuitRoundRect.h"
#include "../InterfaceCircuit/CircuitTextFrame.h"
#include "../InterfaceCircuit/CircuitNetLabel.h"
#include "../InterfaceCircuit/CircuitNoERC.h"
#include "../InterfaceCircuit/CircuitSimStimulus.h"
#include "../InterfaceCircuit/CircuitSimVector.h"
#include "../InterfaceCircuit/CircuitSimProbe.h"
#include "../InterfaceCircuit/CircuitBezier.h"
#include "../InterfaceCircuit/CircuitGraph.h"
#include "../InterfaceCircuit/CircuitPieChart.h"
#include "../InterfaceCircuit/CircuitSimProbe.h"
#include "../InterfaceCircuit/CircuitPort.h"
#include "../InterfaceCircuit/CircuitPortDisObj.h"
#include "../InterfaceCircuit/CircuitLayoutDirective.h"
#include "../InterfaceCircuit/DsnCircuitPartDisObj.h"
#include "RegionGroundLink.h"
#include "../InterfaceCircuit/TinyCADParam.h"

#pragma endregion

using namespace std;

#pragma region

#ifndef PI
#define PI 3.1415926
#endif

void ACAD_EXPORT_TOOL_COMMON_IMPL::GetAngelPos(double xa,double ya,double xb,double yb,double delta_angel,double dLength,double &dRetX1,double &dRetY1,double &dRetX2,double &dRetY2)
{	
	double angel;
	if (fabs((xb-xa))<0.001)
	{
		if(yb-ya>0)
			angel=PI/2;
		else
			angel=PI*3/2;
	}
	else
		angel=atan((yb-ya)/(xb-xa));
	double angelNew1=angel-delta_angel;
	double angelNew2=angel+delta_angel;
	if ((fabs(fabs(angelNew1)-PI/2)< 0.00001 && fabs(fabs(angelNew2)-PI/2)< 0.00001 )
		|| (fabs(fabs(angelNew1)-3*PI/2)< 0.00001 && fabs(fabs(angelNew2)-3*PI/2)< 0.00001))
	{
		dRetX1=dRetX2=xb;
		dRetY1=yb+dLength;
		dRetY2=yb-dLength;
		return;
	}

	double dLen=dLength*dLength; 
	dRetX1= xb-sqrt(dLen/(1+pow(tan(angelNew1),2)));
	dRetX2= xb+sqrt(dLen/(1+pow(tan(angelNew2),2)));
	dRetY1=yb-(xb-dRetX1)*tan(angelNew1);
	dRetY2=yb-(xb-dRetX2)*tan(angelNew2);
	double dTemp1=pow(dRetX1-xb,2)+pow(dRetY1-yb,2)+pow(xb-xa,2)+pow(yb-ya,2)-(pow(dRetX1-xa,2)+pow(dRetY1-ya,2));
	double dTemp2=pow(dRetX2-xb,2)+pow(dRetY2-yb,2)+pow(xb-xa,2)+pow(yb-ya,2)-(pow(dRetX2-xa,2)+pow(dRetY2-ya,2));
	if (dTemp1<0 && fabs(dTemp1) > 0.01)
	{
		dRetX1=xb+sqrt(dLen/(1+pow(tan(angelNew1),2)));
		dRetY1=yb-(xb-dRetX1)*tan(angelNew1);
	}
	if (dTemp2<0 && fabs(dTemp2) > 0.01)
	{
		dRetX2=xb-sqrt(dLen/(1+pow(tan(angelNew2),2)));
		dRetY2=yb-(xb-dRetX2)*tan(angelNew2);
	}
}


double ACAD_EXPORT_TOOL_COMMON_IMPL::GetAngle(double xa,double ya,double xb,double yb)
{
	double angel;
	if (fabs((xb-xa))<0.001)
	{
		if(yb-ya>0)
			angel=PI/2;
		else
			angel=PI*3/2;
	}	
	else if (xb-xa>0)
	{
		angel=atan((yb-ya)/(xb-xa));
	}
	else 
	{
		angel=angel=atan((yb-ya)/(xb-xa));+PI;
	}

	return angel;
}


ACAD_EXPORT_TOOL_COMMON_IMPL::ACAD_EXPORT_TOOL_COMMON_IMPL(void)
{
	m_pAcadApp=NULL;	
	m_pModelSpace = NULL;
}


ACAD_EXPORT_TOOL_COMMON_IMPL::~ACAD_EXPORT_TOOL_COMMON_IMPL(void)
{

}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::Start()
{
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::End()
{
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSystem(CSystem *pSystem)
{	
	::CoInitialize(NULL);

	if(!pSystem)
	{
		pSystem=CModelObjOption::GetIModelObjEventHandler()->GetActiveSystem();
		if(!pSystem)
			return false;
	}
	bool bSucceed=StartAcad();
	if(!bSucceed)
		return false;
	IAcadDocument *pDoc=NULL;	
	m_pAcadApp->get_ActiveDocument(&pDoc);	
	if(!pDoc)
	{		
		AfxMessageBox(_T("请先在AutoCAD中打开一个新文档!"));
		//add by dsq
		if (m_pNumInfo)
		{
			if(!m_pNumInfo->pStartBtn->IsWindowEnabled())
			{
				m_pNumInfo->pStartBtn->EnableWindow(TRUE);
				m_pNumInfo->pStopBtn->EnableWindow(FALSE);
				m_pNumInfo->pListLayer->clear();
				CWnd *pWnd;
				pWnd=CWnd::FromHandle( m_pNumInfo->hwnd);				
				pWnd->Invalidate();
				pWnd->UpdateWindow();
			}
		}

		ShutdownAcad();
		return false;
	}

	//AutoCAD::LONG_PTR lWnd;
	//m_pAcadApp->get_HWND(&lWnd);
	//::SetActiveWindow((HWND)lWnd);
	//::SetFocus((HWND)lWnd);

	pDoc->SetVariable(_bstr_t("LTSCALE"), _variant_t(double(0.1)));

	pDoc->get_ModelSpace(&m_pModelSpace);
	if (!m_pModelSpace)
	{
		return false;
	}
	////////////////////////////////////////////////////////做判断用分层输出，还是全部输出
	if (!GetIsLayeredExport())	//非分层导出
	{
		DoExport(m_pModelSpace, pSystem);				//非分层，此接口中使用自己的进度条对话框,m_pNumInfo没有值
	}	
	else
	{
		DoLayerExport(m_pModelSpace, pSystem);		//分层，此接口中使用选择分层对话框中的进度条对话框 多一个m_pNumInfo参数
	}

	//m_pAcadApp->ZoomAll();
	if (m_pAcadApp)
	{
		m_pAcadApp->ZoomExtents();
	}

	if (pDoc)
	{
		pDoc->Regen(AutoCAD::acAllViewports);
		pDoc->Release();
	}

	VARIANT varit;
	long iCnt = 0;
	// 		IAcadDatabase* pDatabase = NULL;
	// 		m_pModelSpace->get_Database(&pDatabase);
	// 		if (!pDatabase)
	// 			return -1;
	// 		IAcadBlocks* pBlocks = NULL;
	// 		pDatabase->get_Blocks(&pBlocks);
	// 		if (!pBlocks)
	// 			return -1;
	vector<string> vecTexts;
	m_pModelSpace->get_Count(&iCnt);
	IAcadEntity *pEnt = NULL;
	for(int i = 0; i < iCnt; ++i)
	{
		// 			IAcadBlock* pBlock = NULL;
		// 			pBlocks->Item(varit, &pBlock);
		// 			if(!pBlock)
		// 				continue;
		// 			long iBlockCnt = 0;
		// 			pBlock->get_Count(&iBlockCnt);
		// 			for (int j = 0; j < iBlockCnt; ++j)
		// 			{
		varit.iVal = i;
		m_pModelSpace->Item(varit, &pEnt);
		if (!pEnt)
			return false;
		BSTR* pEntName = NULL;
		pEnt->get_EntityName(pEntName);
		if (!pEntName)
			return false;
		string sName = (_bstr_t)pEntName;
		delete pEntName;
		transform(sName.begin(), sName.end(), sName.begin(), toupper);
		if (sName.compare("ACDBTEXT") == 0)				//单行
		{
			IAcadText *pText = dynamic_cast<IAcadText*>(pEnt);
			if (!pText)
				return false;
			BSTR* pTextStr = NULL;
			pText->get_TextString(pTextStr);
			string strText = (_bstr_t)pTextStr;
			vecTexts.push_back(strText);
			delete pTextStr;
		}
		else if (sName.compare("ACDBMTEXT") == 0)		//多行
		{
			IAcadMText *pText = dynamic_cast<IAcadMText*>(pEnt);
			if (!pText)
				return false;
			BSTR* pTextStr = NULL;
			pText->get_TextString(pTextStr);
			string strText = (_bstr_t)pTextStr;
			vecTexts.push_back(strText);
			delete pTextStr;
		}
		//	}

	}


	ShutdownAcad();

	CoUninitialize();
	return true;
}


#ifndef OVERWRITE_FUNCTION_StartAcad
bool ACAD_EXPORT_TOOL_COMMON_IMPL::StartAcad()
{
	CLSID clsid;
	CString str;
	//::CoInitialize(NULL);
	HRESULT h = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);
	if(FAILED(h))
	{
		AfxMessageBox(_T("没有安装AutoCAD软件，无法输出到AutoCAD!"));
		return false;
	}

	IUnknown * pUnknown=NULL;
	h = ::GetActiveObject(clsid, NULL, &pUnknown);//查找是否有AutoCad程序在运行
	if(FAILED(h))
	{
		AfxMessageBox(_T("请先启动AutoCAD程序!"));
		//add by dsq
		if (m_pNumInfo)
		{
			if(!m_pNumInfo->pStartBtn->IsWindowEnabled())
			{
				m_pNumInfo->pStartBtn->EnableWindow(TRUE);
				m_pNumInfo->pStopBtn->EnableWindow(FALSE);
				m_pNumInfo->pListLayer->clear();
				CWnd *pWnd;
				pWnd=CWnd::FromHandle( m_pNumInfo->hwnd);				
				pWnd->Invalidate();
				pWnd->UpdateWindow();
			}
		}
		return false;
		//h = m_AcadApp.CreateDispatch(clsid);      
		//if(FAILED(h)  )   
		//{        
		//	AfxMessageBox("AutoCAD程序打开失败!", "警告");    
		//	return false;     
		//}   
	}
	else
	{
		try
		{
			const GUID r17_app_id = {0x8f17437c,0x2efb,0x4fc4,{0x81,0x88,0xee,0xfa,0x50,0xfe,0x71,0x47}};
			h=pUnknown->QueryInterface(r17_app_id,(void**)&m_pAcadApp);
			if(FAILED(h))
			{
				const GUID app_id = {0x84f323fc,0xc179,0x4704,{0x87,0xe7,0xe3,0xd5,0x76,0xc2,0x59,0x9e}};//acad2010
				h=pUnknown->QueryInterface(app_id,(void**)&m_pAcadApp);

				if( FAILED(h))
				{
					const GUID id = {0x93bc4e71,0xafe7,0x4aa7,{0xbc,0x07,0xf8,0x0a,0xcd,0xb6,0x72,0xd5}};//acad2004
					h=pUnknown->QueryInterface(id,(void**)&m_pAcadApp);

				}
			}
			pUnknown->Release();
			pUnknown=NULL;
		}
		catch(LPCTSTR lpErr)
		{
			AfxMessageBox(lpErr);
			return false;
		}
	}


	if(!m_pAcadApp)
		return false;

	//m_AcadDoc=m_AcadApp.GetActiveDocument();//可能没有当前的文档,提示出错.      
	//m_AcadMSpace = m_AcadDoc.GetModelSpace();     
	//m_pAcadApp->put_Visible(true);
	//IAcadDocuments * pDocs=NULL;
	//m_pAcadApp->get_Documents(&pDocs);

	//pDocs->Release();

	//m_pAcadApp->ZoomAll();
	//CoUninitialize();
	return true;
}
#endif //!OVERWRITE_FUNCTION_StartAcad


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ShutdownAcad()
{
	m_pAcadApp->Release();
	m_pAcadApp=NULL;
	//m_AcadApp.Quit();    
	//m_AcadMSpace.ReleaseDispatch();
	//m_AcadDoc.ReleaseDispatch();
	//m_AcadApp.ReleaseDispatch();

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::DoExport(IAcadModelSpace *pModelSpace, CSystem *pSystem)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	long lCount=0;
	CountDisplayObj(pSystem, lCount);

	long lStepCount=lCount;

	HWND hWnd;
	bool bSucceed=CModelObjOption::GetIModelObjEventHandler()->GetHwnd(hWnd);
	if(bSucceed)
	{
		CWnd *pWnd=CWnd::FromHandle(hWnd);

		pProgressDlg=new CExportProgressDlg(pWnd);
		pProgressDlg->SetPrompt(_T("正在准备导出数据到AutoCAD..."));
		pProgressDlg->SetProgressRange(0, lStepCount);
		pProgressDlg->Create(CExportProgressDlg::IDD, pWnd);
		pProgressDlg->ModifyStyle(WS_CAPTION|WS_BORDER, 0, SWP_DRAWFRAME);

		CRect rc;
		pWnd->GetWindowRect(&rc);
		CRect r;
		pProgressDlg->GetWindowRect(&r);
		int nX=int(0.5*(rc.Width()-r.Width()));
		int nY=int(0.5*(rc.Height()-r.Height()));
		CRect rc1(nX, nY, nX+r.Width(), nY+r.Height());
		pProgressDlg->MoveWindow(&rc1);
		pProgressDlg->ShowWindow(SW_SHOW);
	}
	bool bRet = true;
	const std::list<CLayer *> & LayerList=m_ListLayer;
	std::list<CLayer *>::const_iterator it_layer;
	m_dblViewOffset=0;

	for(it_layer=LayerList.begin(); it_layer!=LayerList.end(); ++it_layer)
	{
		if (pSystem->GetSystemType() != ELECTRIC_SYSTEM)
		{
			if ((*it_layer)->GetLayerLevelType() == TOP_LEVEL_LAYER)
			{
				continue;
			}
		}
		if (IsStopLayerExport())
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		IAcadDatabase *pDatabase=NULL;
		if (!m_pModelSpace)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		m_pModelSpace->get_Database(&pDatabase);
		if ( !pDatabase  )
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}

		IAcadLayers *pLayers=NULL;
		pDatabase->get_Layers(&pLayers);
		pDatabase->Release();
		if ( !pLayers  )
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		IAcadLayer *pLayer=NULL;
		pLayers->Add(_bstr_t((*it_layer)->GetName()), &pLayer);
		pLayer->put_LayerOn(VARIANT_TRUE);
		if ( !pLayer  )
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		IAcadDocument *pDoc=NULL;
		m_pAcadApp->get_ActiveDocument(&pDoc);
		if ( !pDoc  )
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		IAcadLayer *pActiveLayer=NULL;
		pDoc->get_ActiveLayer(&pActiveLayer);
		pDoc->Release();
		if ( !pActiveLayer  )
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		pDoc->put_ActiveLayer(pLayer);
		pLayer->Release();

		if(pActiveLayer)
		{
			pActiveLayer->put_LayerOn(VARIANT_FALSE);	//16 取消注释
			pActiveLayer->Release();
		}

		IAcadDatabase *pDb=NULL;
		if (!m_pModelSpace)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		m_pModelSpace->get_Database(&pDb);
		if ( !pDb  )
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		//输出接口电路图
		IAcadBlocks *pBlocks=NULL;
		pDb->get_Blocks(&pBlocks);
		pDb->Release();	
		if (pBlocks)
		{
			bRet = ExportCircuitAsBlockDef(pBlocks, pSystem, (*it_layer)->GetId(), pProgressDlg);
		}
		pBlocks->Release();
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}

		bRet =					DoExportByLayer(m_pModelSpace, pSystem, (*it_layer)->GetId(), pProgressDlg);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}

		//输出注释
		bRet =				ExportTextAnnotationByLayer(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		//输出图形注释
		bRet =				ExportShapeDisByLayer(*it_layer,m_pModelSpace,pProgressDlg);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		//输出连接关系
		bRet =				ExportSchematicConnectivtyByLayer(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		//输出总线信息
		bRet =				ExportSchematicBusByLayer(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}

		//输出接地桩
		bRet =				ExportGroundUnit(*it_layer, m_pModelSpace);	
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		bRet =		ExportGroundUnit_RegionManager(*it_layer, m_pModelSpace);	
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出接地符号
		bRet =				ExportGroundPatterns(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}

		//输出图纸模板 xiongyb@160907
		bRet =				ExportPageTemplate(*it_layer, m_pModelSpace);	
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
	}
	m_ListLayer.clear();	
	if(pProgressDlg)
	{
		pProgressDlg->SetPrompt(_T("导出完成"));
		pProgressDlg->StepIt();
	}
	DeleteProgressDlg(pProgressDlg);

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::DoExportByLayer(IAcadModelSpace *pModelSpace, CSubSystem *pSystem, long lLayerId, CExportProgressDlg *pProgressDlg)
{ 
	bool bRet = true;
	CSystemDisplayObj *pSystemDisplayObj=(CSystemDisplayObj *)pSystem->GetDisplayObjByLayerID(lLayerId);
	//dsq:
	CSystem *pSystemTemp=dynamic_cast<CSystem *>(pSystem);
	eSystemType systype;
	if (pSystemTemp)
	{
		systype=pSystemTemp->GetSystemType();
	}
	//
	if(pSystemDisplayObj)
	{
		CString szTxt=_T("正在导出：") + pSystemDisplayObj->GetEntityObj()->GetName();
		ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);		

		if(pSystemDisplayObj->IsShowThis())
		{	
			bRet =		ExportSubSystem(m_pModelSpace, pSystemDisplayObj);
			if (!bRet)
			{
				DeleteProgressDlg(pProgressDlg);
				return false;
			}
			CSubSystem * pSubSystem=(CSubSystem *)pSystemDisplayObj->GetEntityObj();
			std::list<CConnector *> ConnectorList=pSubSystem->GetConnectorList();

			std::list<CConnector *>::const_iterator it_conn;
			for(it_conn=ConnectorList.begin(); it_conn!=ConnectorList.end(); ++it_conn)
			{
				if (IsStopLayerExport())
				{
					DeleteProgressDlg(pProgressDlg);
					return false;
				}

				CConnector *pConnector=*it_conn;

				//const std::list<CPin *> & PinList=pConnector->GetPinList();

				CConnectorDisplayObj *pConnectorDisplayObj=(CConnectorDisplayObj *)pConnector->GetDisplayObjByLayerID(lLayerId);
				if(pConnectorDisplayObj && pConnectorDisplayObj->IsShowThis() && pConnectorDisplayObj->IsConnShow())
				{
					bRet =		ExportConnector(m_pModelSpace, pConnectorDisplayObj);
					if (!bRet)
					{
						DeleteProgressDlg(pProgressDlg);
						return false;
					}
					const std::list<CPin *> & PinList=pConnector->GetPinList();
					std::list<CPin *>::const_iterator it_pin;
					for(it_pin=PinList.begin(); it_pin!=PinList.end(); ++it_pin)
					{
						CPin *pPin=*it_pin;
						if (IsStopLayerExport())
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
						CPinDisplayObj *pPinDisplayObj=(CPinDisplayObj *)pPin->GetDisplayObjByLayerID(lLayerId);
						if(pPinDisplayObj && pPinDisplayObj->IsShowThis())
							bRet =				ExportPin(m_pModelSpace, pPinDisplayObj);
						if (!bRet)
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
					}
				}
			}
			//输出自电缆显示对象;
			list<CCable*> lstCable=pSystem->GetCableList();
			for (list<CCable*>::iterator iter_cable=lstCable.begin();iter_cable!=lstCable.end();iter_cable++)
			{
				list<CSubCable*> lstSubCable=(*iter_cable)->GetSubCableList();
				for (list<CSubCable*>::iterator iter_subCable=lstSubCable.begin();iter_subCable!=lstSubCable.end();iter_subCable++)
				{
					if (IsStopLayerExport())
					{
						DeleteProgressDlg(pProgressDlg);
						return false;
					}
					CSubCableDisplayObj* pSubCableDis=(CSubCableDisplayObj*)(*iter_subCable)->GetDisplayObjByLayerID(lLayerId);
					if (pSubCableDis && pSubCableDis->IsShowThis())
					{
						bRet =				ExportSubCable(m_pModelSpace, pSubCableDis);
						if (!bRet)
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
					}
				}
			}
		}
	}

	//分系统背景？
	CBackgroundDisplayObj * pBackgroundDisplayObj=pSystem->GetBackgroundDisplayObjByLayerId(lLayerId);
	if(pBackgroundDisplayObj && pBackgroundDisplayObj->IsShowThis())
	{
		bRet =				ExportSubSystemBackground(m_pModelSpace, pBackgroundDisplayObj);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
	}

	const std::list<CSubSystem *> & SubSystemList=pSystem->GetSubSystemList();
	std::list<CSubSystem *>::const_iterator it_subsystem;
	for(it_subsystem=SubSystemList.begin(); it_subsystem!=SubSystemList.end(); ++it_subsystem)
	{
		if (IsStopLayerExport())
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		CSubSystem *pSubSystem=*it_subsystem;
		//CSystemDisplayObj *pSystemDisplayObj=(CSystemDisplayObj *)pSubSystem->GetDisplayObjByLayerID(lLayerId);
		//if(pSystemDisplayObj)
		//	ExportSubSystem(m_pModelSpace, pSystemDisplayObj);

		bRet =				DoExportByLayer(m_pModelSpace, *it_subsystem, lLayerId, pProgressDlg);
		if (!bRet)
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
	}

	const std::list<CDevice *> & DeviceList=pSystem->GetDeviceList();
	std::list<CDevice *>::const_iterator it_device;
	for(it_device=DeviceList.begin(); it_device!=DeviceList.end(); ++it_device)
	{
		if (IsStopLayerExport())
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		CDevice *pDevice=*it_device;
		CDeviceDisplayObj *pDeviceDisplayObj=(CDeviceDisplayObj *)pDevice->GetDisplayObjByLayerID(lLayerId);
		if(pDeviceDisplayObj)
		{
			CString szTxt=_T("正在导出：")+pDeviceDisplayObj->GetEntityObj()->GetName();
			ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	
		}
		if(pDeviceDisplayObj && pDeviceDisplayObj->IsShowThis())
		{
			bRet =				ExportDevice(m_pModelSpace, pDeviceDisplayObj);
			if (!bRet)
			{
				DeleteProgressDlg(pProgressDlg);
				return false;
			}
			const std::list<CConnector *> & ConnectorList=pDevice->GetConnectorList();
			std::list<CConnector *>::const_iterator it_conn;
			for(it_conn=ConnectorList.begin(); it_conn!=ConnectorList.end(); ++it_conn)
			{
				if (IsStopLayerExport())
				{
					DeleteProgressDlg(pProgressDlg);
					return false;
				}
				CConnector *pConnector=*it_conn;
				//const std::list<CPin *> & PinList=pConnector->GetPinList();

				CConnectorDisplayObj *pConnectorDisplayObj=(CConnectorDisplayObj *)pConnector->GetDisplayObjByLayerID(lLayerId);
				if(pConnectorDisplayObj && pConnectorDisplayObj->IsShowThis() && pConnectorDisplayObj->IsConnShow())
				{
					bRet =				ExportConnector(m_pModelSpace, pConnectorDisplayObj);
					if (!bRet)
					{
						DeleteProgressDlg(pProgressDlg);
						return false;
					}
					const std::list<CPin *> & PinList=pConnector->GetPinList();
					std::list<CPin *>::const_iterator it_pin;
					for(it_pin=PinList.begin(); it_pin!=PinList.end(); ++it_pin)
					{
						if (IsStopLayerExport())
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
						CPin *pPin=*it_pin;
						CPinDisplayObj *pPinDisplayObj=(CPinDisplayObj *)pPin->GetDisplayObjByLayerID(lLayerId);
						if(pPinDisplayObj && pPinDisplayObj->IsShowThis())
							bRet =				ExportPin(m_pModelSpace, pPinDisplayObj);
						if (!bRet)
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
					}
				}
			}

		}
	}

	const std::list<CConnector *> & ConnectorList=pSystem->GetConnectorList();
	std::list<CConnector *>::const_iterator it_conn;
	for(it_conn=ConnectorList.begin(); it_conn!=ConnectorList.end(); ++it_conn)
	{
		if (IsStopLayerExport())
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		CConnector *pConnector=*it_conn;
		//dsq：电缆分支走向层
		if (pConnector->IsSubCableConnector()&&systype==CABLE_PATH_BRANCHES_SYSTEM)
		{
			//设置管脚的显示文本;
			list<CPin*> lstPins=pConnector->GetPinList();
			for (list<CPin*>::iterator iter_pin=lstPins.begin();iter_pin!=lstPins.end();iter_pin++)
			{
				if (IsStopLayerExport())
				{
					DeleteProgressDlg(pProgressDlg);
					return false;
				}
				CPin* pPin=*iter_pin;
				CPinDisplayObj* pPinDis=(CPinDisplayObj*)pPin->GetDisplayObjByLayerID(lLayerId);
				if (pPinDis)
				{
					list<CWire*> lstWire;					
					CSystem* pBigdrawing=pConnector->GetBigDrawing();
					pBigdrawing->GetAssociatedWires(pPin,pPinDis->GetLayerId(),lstWire); 
					CString szPinName(_T(""));
					for (list<CWire*>::iterator iter=lstWire.begin();iter!=lstWire.end();iter++)
					{
						szPinName=szPinName+(*iter)->GetSignalName()+_T(",");
					}
					szPinName.TrimRight(_T(","));
					pPinDis->SetAliasName(szPinName);
				}
			}
		}
		//

		CConnectorDisplayObj *pConnectorDisplayObj=(CConnectorDisplayObj *)pConnector->GetDisplayObjByLayerID(lLayerId);
		if(pConnectorDisplayObj)
		{
			CString szTxt=_T("正在导出：")+pConnectorDisplayObj->GetEntityObj()->GetName();
			ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);			
		}

		if(pConnectorDisplayObj && pConnectorDisplayObj->IsShowThis() && pConnectorDisplayObj->IsConnShow())
		{
			bRet =				ExportConnector(m_pModelSpace, pConnectorDisplayObj);
			if (!bRet)
			{
				DeleteProgressDlg(pProgressDlg);
				return false;
			}

			const std::list<CPin *> & PinList=pConnector->GetPinList();
			std::list<CPin *>::const_iterator it_pin;
			for(it_pin=PinList.begin(); it_pin!=PinList.end(); ++it_pin)
			{
				if (IsStopLayerExport())
				{
					DeleteProgressDlg(pProgressDlg);
					return false;
				}
				CPin *pPin=*it_pin;
				CPinDisplayObj *pPinDisplayObj=(CPinDisplayObj *)pPin->GetDisplayObjByLayerID(lLayerId);
				if(pPinDisplayObj && pPinDisplayObj->IsShowThis())
				{
					if (pConnector->IsSubCableConnector()&&systype==CABLE_PATH_BRANCHES_SYSTEM)
					{
						bRet =				ExportCableBranchePin(m_pModelSpace, pPinDisplayObj);
						if (!bRet)
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
					}
					else
					{
						bRet =				ExportPin(m_pModelSpace, pPinDisplayObj);
						if (!bRet)
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
					}
				}
			}
		}
	}

	const std::list<CCable *> & CableList=pSystem->GetCableList();
	std::list<CCable *>::const_iterator it_cable;
	for(it_cable=CableList.begin(); it_cable!=CableList.end(); ++it_cable)
	{
		if (IsStopLayerExport())
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		CCable *pCable=*it_cable;
		const std::list<CSubCable *> & SubCableList=pCable->GetSubCableList();
		std::list<CSubCable *>::const_iterator it_subcable;
		//dsq:导出提取的电缆分支走向图 pSystemDisplayObj为空			
		for (it_subcable=SubCableList.begin();it_subcable!=SubCableList.end();it_subcable++)
		{
			if (IsStopLayerExport())
			{
				DeleteProgressDlg(pProgressDlg);
				return false;
			}
			CSubCableDisplayObj* pSubCableDis=(CSubCableDisplayObj*)(*it_subcable)->GetDisplayObjByLayerID(lLayerId);
			if (pSubCableDis&&systype==CABLE_PATH_BRANCHES_SYSTEM && pSubCableDis->IsShowThis())
			{
				bRet =				ExportCableBranches(m_pModelSpace, pSubCableDis);
				if (!bRet)
				{
					DeleteProgressDlg(pProgressDlg);
					return false;
				}
			}
		}		
		//
		for(it_subcable=SubCableList.begin(); it_subcable!=SubCableList.end(); ++it_subcable)
		{
			if (IsStopLayerExport())
			{
				DeleteProgressDlg(pProgressDlg);
				return false;
			}
			CSubCable *pSubCable=*it_subcable;
			CString szTxt=_T("正在导出：")+pSubCable->GetName();
			ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

			const std::list<CWire *> & WireList=pSubCable->GetWireList();
			std::list<CWire *>::const_iterator it_wire;
			for(it_wire=WireList.begin(); it_wire!=WireList.end(); ++it_wire)
			{
				if (IsStopLayerExport())
				{
					DeleteProgressDlg(pProgressDlg);
					return false;
				}
				CWire *pWire=*it_wire;
				CWireDisplayObj *pWireDisplayObj=(CWireDisplayObj *)pWire->GetDisplayObjByLayerID(lLayerId);
				if(pWireDisplayObj && pWireDisplayObj->IsShowThis())
				{
					//	if(pWireDisplayObj->IsFilterByWirestyle())
					{
						bRet =					ExportWire(m_pModelSpace, pWireDisplayObj);
						if (!bRet)
						{
							DeleteProgressDlg(pProgressDlg);
							return false;
						}
					}
				}
			}
		}
	}

	//对连接线的输出  lww 
	const std::list<CSubline *>& subLineList = pSystem->GetSublineList();
	std::list<CSubline *>::const_iterator it_subLine;
	for(it_subLine=subLineList.begin(); it_subLine!=subLineList.end(); ++it_subLine)
	{
		if (IsStopLayerExport())
		{
			DeleteProgressDlg(pProgressDlg);
			return false;
		}
		CSubline *pSubline = *it_subLine;
		CSublineDisplayObj* pSublineDisObj = (CSublineDisplayObj*)pSubline->GetDisplayObjByLayerID(lLayerId);
		if( pSublineDisObj && pSublineDisObj->IsShowThis() )
		{
			bRet =				ExportSubline(m_pModelSpace,pSublineDisObj);
			if (!bRet)
			{
				DeleteProgressDlg(pProgressDlg);
				return false;
			}
		}
	}  

	//输出分支绑扎点;
	if (pSystemTemp)
	{
		CLayer* pLayer = pSystemTemp->GetLayerByID(lLayerId);
		if (pLayer)
		{
			list<CSubCableTying*> lstTying = pLayer->GetSubCableTyingLst();
			list<CSubCableTying*>::iterator iter= lstTying.begin();
			for (;iter!= lstTying.end();iter++)
			{
				CSubCableTyingDisObj* pTyingDis = (CSubCableTyingDisObj*)(*iter)->GetDisplayObjByLayerID(lLayerId);
				if (pTyingDis)
				{
					ExportSubCableTyingPt(pModelSpace, pTyingDis);
				}
			}
		}
	}

	return bRet;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSubSystem(IAcadModelSpace *pModelSpace, const CSystemDisplayObj *pSystemDisplayObj) const
{
	eDevAndSysShowStyle eShowStyle = pSystemDisplayObj->GetShowStyle();
	if (eShowStyle == ShowNone)
	{
		return true;
	}
	CSubSystem *pSystem=(CSubSystem *)pSystemDisplayObj->GetEntityObj();
	double dblCenterX=pSystemDisplayObj->GetPosX()+m_dblViewOffset;
	double dblCenterY=pSystemDisplayObj->GetPosY();
	double dblHalfWidth=pSystemDisplayObj->GetWidth()*0.5;
	double dblHalfHeight=pSystemDisplayObj->GetHeight()*0.5;

	//子系统边框修改为矩形  lww 2013.12.3
	double pts[]={	dblCenterX-dblHalfWidth, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight, 0,
		dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 12, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts; 
	if (!pvPts)
		return false;
	if(!pModelSpace)
		return false;
	IAcadPolyline *pPolyline=NULL;	
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	VARIANT varit;
	varit.lVal = 0;
	IAcadEntity* pEnt = NULL;
	m_pModelSpace->Item(varit,& pEnt);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_TRUE); 

	//线型
	IAcadDatabase *pDatabase=NULL;
	m_pModelSpace->get_Database(&pDatabase);
	if(!pDatabase)
		return false;
	IAcadLineTypes *pLineTypes=NULL;
	pDatabase->get_Linetypes(&pLineTypes);
	if(!pLineTypes)
		return false;
	switch(eShowStyle)
	{
	case ShowTitle:
		{
			if(!ExistLineType(pLineTypes, _T("DIVIDE")))
				pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
			pPolyline->put_Linetype(_bstr_t("DIVIDE"));
		}

		break;
	case ShowDotBorder:
		{
			if(!ExistLineType(pLineTypes, _T("HIDDEN")))
				pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
			pPolyline->put_Linetype(_bstr_t("HIDDEN"));
		}
		break;
	}

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pSystemDisplayObj->GetColorR()*255), (long)(pSystemDisplayObj->GetColorG()*255), (long)(pSystemDisplayObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}
	IAcadHatch *pHatch=NULL;
	if (eShowStyle == ShowTitle)				//显示边框或者都不显示 就不用画了 
	{
		m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
		if(pHatch)
		{
			IAcadAcCmColor *pHatchColor=GetColor();
			if(pHatchColor)
			{
				pHatchColor->SetRGB((long)(pSystemDisplayObj->GetFillColorR()*255), (long)(pSystemDisplayObj->GetFillColorG()*255), (long)(pSystemDisplayObj->GetFillColorB()*255));
				pHatch->put_TrueColor(pHatchColor);
				pHatchColor->Release();
			}

			COleSafeArray saLoop;
			//IDispatch * ent_array[]={pPolyline};
			saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
			VARIANT * pvLoop=(LPVARIANT)saLoop;

			pHatch->AppendOuterLoop(*pvLoop);
			// pHatch->put_AssociativeHatch(TRUE);		 
			pHatch->Release();
		}
	}

	//输出Title框及框内文字,顶层及分系统层无Title框
	double dblTileHeight = pSystemDisplayObj->GetTitleHeight();
	long layerId = pSystemDisplayObj->GetLayerId();
	CLayer* pLayer = pSystem->GetBigDrawing()->GetLayerByID(layerId);
	if (
		(!pLayer->IsSubsysSkematicLayer()&&!pSystem->IsSystem())
		||(pLayer->IsSubsysSkematicLayer()&&pSystemDisplayObj->IsShowInnerDevice())//分系统示意层并显示内部设备
		)
	{
		double titlePts[]={	dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight-dblTileHeight, 0,
			dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight-dblTileHeight, 0,
			dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight, 0,
			dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight, 0,
		};
		if (eShowStyle == ShowTitle)
		{
			COleSafeArray  saTitlePts;
			saTitlePts.CreateOneDim(VT_R8, 12, titlePts);        
			VARIANT * pvTitlePt =  (LPVARIANT)saTitlePts;
			m_pModelSpace->AddPolyline(*pvTitlePt, &pPolyline);
			if(!pPolyline)
				return false;
			pPolyline->put_Closed(VARIANT_TRUE);
			pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pSystemDisplayObj->GetColorR()*255), (long)(pSystemDisplayObj->GetColorG()*255), (long)(pSystemDisplayObj->GetColorB()*255));
				pPolyline->put_TrueColor(pColor);
				pColor->Release();
			}
			pHatch=NULL;
			m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
			if(pHatch)
			{
				IAcadAcCmColor *pHatchColor=GetColor();
				if(pHatchColor)
				{
					pHatchColor->SetRGB((long)(pSystemDisplayObj->GetTitleFillClrR()*255), (long)(pSystemDisplayObj->GetTitleFillClrG()*255), (long)(pSystemDisplayObj->GetTitleFillClrB()*255));
					pHatch->put_TrueColor(pHatchColor);
					pHatchColor->Release();
				}

				COleSafeArray saLoop;
				//IDispatch * ent_array[]={pPolyline};
				saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
				VARIANT * pvLoop=(LPVARIANT)saLoop;
				pHatch->AppendOuterLoop(*pvLoop);			

				pHatch->Release();
			}
		}

		double dblTextHeight= pSystemDisplayObj->GetTextSize();
		double insert_pts[]={dblCenterX-/*2.5*/1*dblHalfWidth, dblCenterY+dblHalfHeight-0.2*dblTextHeight, 0};
		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		IAcadMText *pMText=NULL;
		m_pModelSpace->AddMText(*pvInsertPts, /*5*/2*dblHalfWidth, _bstr_t(pSystem->GetName()), &pMText);
		if(pMText)
		{
			/*IAcadAcCmColor **/pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pSystemDisplayObj->GetTextColorR()*255), (long)(pSystemDisplayObj->GetTextColorG()*255), (long)(pSystemDisplayObj->GetTextColorB()*255));
				pMText->put_TrueColor(pColor);
				pColor->Release();
			}
			pMText->put_Height(0.9*dblTextHeight);
			pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
			CString strTextFont=pSystemDisplayObj->GetTextFont();
			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
			if(!strTextStyle.IsEmpty())
				pMText->put_StyleName(_bstr_t(strTextStyle));
			pMText->Release();
		}
	}
	else if(pLayer->IsSubsysSkematicLayer()&&!pSystemDisplayObj->IsShowInnerDevice())//输出分系统示意层文字
	{
		double dblTextHeight= pSystemDisplayObj->GetTextSize();
		double insert_pts[]={dblCenterX-dblHalfWidth, dblCenterY+0.5*dblTextHeight, 0};
		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		IAcadMText *pMText=NULL;
		m_pModelSpace->AddMText(*pvInsertPts, 2*dblHalfWidth, _bstr_t(pSystem->GetName()), &pMText);
		if(pMText)
		{
			/*IAcadAcCmColor **/pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pSystemDisplayObj->GetTextColorR()*255), (long)(pSystemDisplayObj->GetTextColorG()*255), (long)(pSystemDisplayObj->GetTextColorB()*255));
				pMText->put_TrueColor(pColor);
				pColor->Release();
			}
			pMText->put_Height(0.9*dblTextHeight);
			pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
			CString strTextFont=pSystemDisplayObj->GetTextFont();
			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
			if(!strTextStyle.IsEmpty())
				pMText->put_StyleName(_bstr_t(strTextStyle));
			pMText->Release();
		}
	}
	CTextDisplayObj *pTextDisplayObj=pSystemDisplayObj->GetTextDisObj();
	if(pTextDisplayObj && pTextDisplayObj->IsVisible())
	{
		double dblTextHeight=pTextDisplayObj->GetTextSize();

		CSubSystem *pSystem=(CSubSystem *)pSystemDisplayObj->GetEntityObj();
		double insert_pts[]={dblCenterX, dblCenterY+0.5*dblTextHeight, 0};
		if( pSystem->IsSystem() )
		{
			insert_pts[0]=pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX()-dblHalfWidth;;
			insert_pts[1]=pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY()+0.5*dblTextHeight;
		}
		else
		{
			insert_pts[0]=pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX();
			insert_pts[1]=pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY()+0.5*dblTextHeight;
		}


		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;

		IAcadMText *pMText=NULL;
		m_pModelSpace->AddMText(*pvInsertPts, 2*dblHalfWidth, _bstr_t(pSystem->GetName()), &pMText);
		if(pMText)
		{
			/*IAcadAcCmColor **/pColor=GetColor();
			if(pColor)
			{
				if(pTextDisplayObj)
					pColor->SetRGB((long)(pTextDisplayObj->GetTextColorR()*255), (long)(pTextDisplayObj->GetTextColorG()*255), (long)(pTextDisplayObj->GetTextColorB()*255));
				else
					pColor->SetRGB((long)(pSystemDisplayObj->GetTextColorR()*255), (long)(pSystemDisplayObj->GetTextColorG()*255), (long)(pSystemDisplayObj->GetTextColorB()*255));
				pMText->put_TrueColor(pColor);
				pColor->Release();
			}
			pMText->put_Height(0.9*dblTextHeight);
			if( pSystem->IsSystem() )
			{
				pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
			}
			else
			{
				pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleLeft);
			}
			CString strTextFont=pSystemDisplayObj->GetTextFont();
			if(pTextDisplayObj)
				strTextFont=pTextDisplayObj->GetTextFont();
			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
			if(!strTextStyle.IsEmpty())
				pMText->put_StyleName(_bstr_t(strTextStyle));
			pMText->Release();
		}
	} 
	if(!pSystemDisplayObj->GetPicName().IsEmpty())
	{
		double insert_pts[]={dblCenterX-dblHalfWidth, dblCenterY-dblHalfHeight/*+dblTileHeight*/, 0};

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPt =  (LPVARIANT)saInsertPts;

		CString strPicFile(pSystemDisplayObj->GetPicName());

		CImageProp *pImageProp=pSystemDisplayObj->GetEntityObj()->GetBigDrawing()->GetImageProp(strPicFile);
		if(pImageProp)
		{
			int nIndex=strPicFile.ReverseFind(_T('\\'));
			if(nIndex!=-1 && nIndex+1<strPicFile.GetLength())
			{				
				CString strNewPicFile=strPicFile.Mid(nIndex+1);
				CString strExportDir = CModelObjOption::GetExportPicPath();
				if (strExportDir.ReverseFind(_T('\\')) != strExportDir.GetLength() - 1)
				{
					strExportDir = strExportDir + _T("\\");
				}
				strNewPicFile=strExportDir+strNewPicFile;
				pImageProp->Save(strNewPicFile);

				IAcadRasterImage *pImage=NULL;
				m_pModelSpace->AddRaster(_bstr_t(strNewPicFile), *pvInsertPt, 1.0, 0, &pImage);
				if(pImage)
				{
					pImage->put_ImageWidth(pSystemDisplayObj->GetWidth());
					//dsq:CAD系统图片会覆盖掉系统的标题栏,添加-dblTileHeight
					pImage->put_ImageHeight(pSystemDisplayObj->GetHeight()-dblTileHeight);

					pImage->Release();
				}
			}
		}
	} 	

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSubSystemBackground(IAcadModelSpace *pModelSpace, const CBackgroundDisplayObj *pBackgroundDisplayObj) const
{
	double dblCenterX=pBackgroundDisplayObj->GetPosX()+m_dblViewOffset;
	double dblCenterY=pBackgroundDisplayObj->GetPosY();
	double dblHalfWidth=pBackgroundDisplayObj->GetWidth()*0.5;
	double dblHalfHeight=pBackgroundDisplayObj->GetHeight()*0.5;

	double dblRadius = 0.15 * min(pBackgroundDisplayObj->GetWidth(), pBackgroundDisplayObj->GetHeight());
	double pts[]={	dblCenterX-dblHalfWidth+dblRadius, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth-dblRadius, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth, dblCenterY-dblHalfHeight+dblRadius, 0,
		dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight-dblRadius, 0,
		dblCenterX+dblHalfWidth-dblRadius, dblCenterY+dblHalfHeight, 0,
		dblCenterX-dblHalfWidth+dblRadius, dblCenterY+dblHalfHeight, 0,
		dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight-dblRadius, 0,
		dblCenterX-dblHalfWidth, dblCenterY-dblHalfHeight+dblRadius, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 24, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	if(!pModelSpace)
		return false;
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_TRUE);

	//pPolyline->put_ConstantWidth(0.25);
	double dblBulge=tan(PI*0.125);
	pPolyline->SetBulge(1, dblBulge);
	pPolyline->SetBulge(3, dblBulge);
	pPolyline->SetBulge(5, dblBulge);
	pPolyline->SetBulge(7, dblBulge);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pBackgroundDisplayObj->GetColorR()*255), (long)(pBackgroundDisplayObj->GetColorG()*255), (long)(pBackgroundDisplayObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	CSubSystem *pSystem=pBackgroundDisplayObj->GetRefSubsys();
	const std::list<CDisplayObj *> & DisplayObjList=pSystem->GetDisplayObjList();
	CSystemDisplayObj *pSystemDisplayObj=NULL;
	if(!DisplayObjList.empty())
		pSystemDisplayObj=(CSystemDisplayObj *)DisplayObjList.front();

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			if(pSystemDisplayObj)
			{
				long r=(long)(pSystemDisplayObj->GetFillColorR()*255);
				long g=(long)(pSystemDisplayObj->GetFillColorG()*255);
				long b=(long)(pSystemDisplayObj->GetFillColorB()*255);
				long max_rgb=max(r, g);
				max_rgb=max(max_rgb, b);
				if(max_rgb>0 && max_rgb<232)
				{
					double scale=232.0/(double)max_rgb;
					r=(long)(r*scale);
					g=(long)(g*scale);
					b=(long)(b*scale);
				}
				pColor->SetRGB(r, g, b);
			}
			else
				pColor->SetRGB(232, 232, 232);
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}

		COleSafeArray saLoop;
		//IDispatch * ent_array[]={pPolyline};
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
		VARIANT * pvLoop=(LPVARIANT)saLoop;

		pHatch->AppendOuterLoop(*pvLoop);

		pHatch->Release();
	}

	//double dblTextHeight=pBackgroundDisplayObj->GetTextSize();
	//if(pSystemDisplayObj)
	//	dblTextHeight=pSystemDisplayObj->GetTextSize();
	CTextDisplayObj *pTextDisplayObj=pBackgroundDisplayObj->GetTextDisObj();
	if(pTextDisplayObj && pTextDisplayObj->IsVisible())
	{
		double dblTextHeight=pTextDisplayObj->GetTextSize();
		dblTextHeight/=CTextDisplayObj::GetThreshold();
		double insert_pts[]={dblCenterX-dblHalfWidth, dblCenterY+0.5*dblTextHeight, 0};
		insert_pts[0]=pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX()-dblHalfWidth;
		insert_pts[1]=pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY()+0.5*dblTextHeight;

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		IAcadMText *pMText=NULL;
		m_pModelSpace->AddMText(*pvInsertPts, 2*dblHalfWidth, _bstr_t(pSystem->GetName()), &pMText);
		if(pMText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				if(pTextDisplayObj)
					pColor->SetRGB((long)(pTextDisplayObj->GetTextColorR()*255), (long)(pTextDisplayObj->GetTextColorG()*255), (long)(pTextDisplayObj->GetTextColorB()*255));
				else
					pColor->SetRGB((long)(pBackgroundDisplayObj->GetTextColorR()*255), (long)(pBackgroundDisplayObj->GetTextColorG()*255), (long)(pBackgroundDisplayObj->GetTextColorB()*255));
				pMText->put_TrueColor(pColor);
				pColor->Release();
			}
			pMText->put_Height(dblTextHeight);
			pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);

			CString strTextFont=pBackgroundDisplayObj->GetTextFont();
			if(pTextDisplayObj)
				strTextFont=pTextDisplayObj->GetTextFont();
			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
			if(!strTextStyle.IsEmpty())
				pMText->put_StyleName(_bstr_t(strTextStyle));
			pMText->Release();
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportDevice(IAcadModelSpace *pModelSpace, const CDeviceDisplayObj *pDeviceDisplayObj) const
{		
	eDevAndSysShowStyle eShowStyle = pDeviceDisplayObj->GetShowStyle();
	CDevice *pDevice=(CDevice *)pDeviceDisplayObj->GetEntityObj();

	double dblCenterX=pDeviceDisplayObj->GetPosX()+m_dblViewOffset;
	double dblCenterY=pDeviceDisplayObj->GetPosY();
	double dblHalfWidth=pDeviceDisplayObj->GetWidth()*0.5;
	double dblHalfHeight=pDeviceDisplayObj->GetHeight()*0.5;
	double pts[]={	dblCenterX-dblHalfWidth, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight, 0,
		dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight, 0,
	};
	double dblTileHeight = pDeviceDisplayObj->GetTitleHeight();
	if (eShowStyle != ShowNone)
	{
		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, 12, pts);        
		VARIANT * pvPts =  (LPVARIANT)saPts;     
		if(!pModelSpace)
			return false;
		IAcadPolyline *pPolyline=NULL;
		m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
		if(!pPolyline)	return false;
		pPolyline->put_Closed(VARIANT_TRUE);

		pPolyline->put_ConstantWidth(0.25);

		//线型
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)	return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);
		if(!pLineTypes)	return false;

		switch(eShowStyle)
		{
		case ShowTitle:
			break;
		case ShowDotBorder:
			{
				/*if(!ExistLineType(pLineTypes, _T("DIVIDE")))
					pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
				pPolyline->put_Linetype(_bstr_t("DIVIDE"));*/
			}
			break;
		case ShowNone:
			{
				if(!ExistLineType(pLineTypes, _T("HIDDEN")))
					pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
				pPolyline->put_Linetype(_bstr_t("HIDDEN"));
			}
			break;
		}
		IAcadAcCmColor *pColor=GetColor();
		if (eShowStyle != ShowNone)
		{
			if(pColor)
			{
				pColor->SetRGB((long)(pDeviceDisplayObj->GetColorR()*255), (long)(pDeviceDisplayObj->GetColorG()*255), (long)(pDeviceDisplayObj->GetColorB()*255));
				pPolyline->put_TrueColor(pColor);
				pColor->Release();
			}

		}
		IAcadHatch *pHatch=NULL;
		if(eShowStyle == ShowTitle)
		{
			m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
			if(pHatch)
			{
				IAcadAcCmColor *pColor=GetColor();
				if(pColor)
				{
					pColor->SetRGB((long)(pDeviceDisplayObj->GetFillColorR()*255), (long)(pDeviceDisplayObj->GetFillColorG()*255), (long)(pDeviceDisplayObj->GetFillColorB()*255));
					pHatch->put_TrueColor(pColor);
					pColor->Release();
				}

				COleSafeArray saLoop;
				//IDispatch * ent_array[]={pPolyline};
				saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
				VARIANT * pvLoop=(LPVARIANT)saLoop;

				pHatch->AppendOuterLoop(*pvLoop);


				pHatch->Release();
			}
		}
		if (pDevice->IsProxyDevice() ==false &&
			(eShowStyle == ShowTitle || eShowStyle == ShowDotBorder))
		{
			if (eShowStyle == ShowTitle)
			{
				//输出Title框
				double titlePts[]={	dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight-dblTileHeight, 0,
					dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight-dblTileHeight, 0,
					dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight, 0,
					dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight, 0,
				};
				COleSafeArray  saTitlePts;
				saTitlePts.CreateOneDim(VT_R8, 12, titlePts);	
				VARIANT * pvTitlePt =  (LPVARIANT)saTitlePts;	
				if (!m_pModelSpace)
					return false;
				m_pModelSpace->AddPolyline(*pvTitlePt, &pPolyline);
				if(!pPolyline) return false;
				pPolyline->put_Closed(VARIANT_TRUE);

				pColor=GetColor();
				if(pColor)
				{
					pColor->SetRGB((long)(pDeviceDisplayObj->GetColorR()*255), (long)(pDeviceDisplayObj->GetColorG()*255), (long)(pDeviceDisplayObj->GetColorB()*255));
					pPolyline->put_TrueColor(pColor);
					pColor->Release();
				}
				pHatch=NULL;

				m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
				if(pHatch)
				{
					/*IAcadAcCmColor **/pColor=GetColor();
					if(pColor)
					{
						pColor->SetRGB((long)(pDeviceDisplayObj->GetTitleFillClrR()*255), (long)(pDeviceDisplayObj->GetTitleFillClrG()*255), (long)(pDeviceDisplayObj->GetTitleFillClrB()*255));
						pHatch->put_TrueColor(pColor);
						pColor->Release();
					}

					COleSafeArray saLoop;
					//IDispatch * ent_array[]={pPolyline};
					saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
					VARIANT * pvLoop=(LPVARIANT)saLoop;
					pHatch->AppendOuterLoop(*pvLoop);

					pHatch->Release();
				}

			}
			//输出Title框中的文字；比例不一致，文字预设宽度增大一倍;
			double dbTitleHeight = pDeviceDisplayObj->GetTitleHeight();
			double dblTextHeight= pDeviceDisplayObj->GetTextSize();
			while (dblTextHeight*2 > dbTitleHeight -4)
			{
				dblTextHeight --;
			}
			double insert_pts[]={dblCenterX-/*2*/1*dblHalfWidth, dblCenterY+dblHalfHeight - 0.125*dbTitleHeight, 0};
			COleSafeArray   saInsertPts;
			VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
			IAcadMText *pMText=NULL;
			saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
			pvInsertPts =  (LPVARIANT)saInsertPts;
			pMText=NULL;
			m_pModelSpace->AddMText(*pvInsertPts, /*4*/2*dblHalfWidth, _bstr_t(pDevice->GetName()), &pMText);
			if(pMText)
			{
				IAcadAcCmColor *pColor=GetColor();
				if(pColor)
				{
					pColor->SetRGB((long)(pDeviceDisplayObj->GetTextColorR()*255), (long)(pDeviceDisplayObj->GetTextColorG()*255), (long)(pDeviceDisplayObj->GetTextColorB()*255));
					pMText->put_TrueColor(pColor);
					pColor->Release();
				}
				pMText->put_Height(0.8*dblTextHeight);
				pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
				CString strTextFont=pDeviceDisplayObj->GetTextFont();
				CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
				if(!strTextStyle.IsEmpty())
					pMText->put_StyleName(_bstr_t(strTextStyle));
				pMText->Release();
			}

			//代号
			double insert_pts1[]={dblCenterX-2*dblHalfWidth, dblCenterY+dblHalfHeight - 0.6*dbTitleHeight, 0};
			COleSafeArray   saInsertPts1;
			VARIANT * pvInsertPts1 =  (LPVARIANT)saInsertPts1;
			IAcadMText *pMText1=NULL;
			saInsertPts1.CreateOneDim(VT_R8, 3, insert_pts1);        
			pvInsertPts1 =  (LPVARIANT)saInsertPts1;
			pMText1=NULL;
			m_pModelSpace->AddMText(*pvInsertPts1, 4*dblHalfWidth, _bstr_t(CString("(")+pDevice->GetNo()+_T(")")), &pMText1);
			if(pMText1)
			{
				IAcadAcCmColor *pColor=GetColor();
				if(pColor)
				{
					pColor->SetRGB((long)(pDeviceDisplayObj->GetTextColorR()*255), (long)(pDeviceDisplayObj->GetTextColorG()*255), (long)(pDeviceDisplayObj->GetTextColorB()*255));
					pMText1->put_TrueColor(pColor);
					pColor->Release();
				}
				pMText1->put_Height(0.8*dblTextHeight);
				pMText1->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
				CString strTextFont=pDeviceDisplayObj->GetTextFont();
				CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
				if(!strTextStyle.IsEmpty())
					pMText1->put_StyleName(_bstr_t(strTextStyle));
				pMText1->Release();
			}
		}

	}

	std::list<CEntityObj *> ICircuitList;
	pDevice->GetICircuitContentList(ICircuitList);
	if(!ICircuitList.empty())
	{
		std::list<CEntityObj *>::iterator iter;
		for(iter=ICircuitList.begin(); iter!=ICircuitList.end(); ++iter)
		{					
			if(!(*iter)->IsICircuit())
				continue;

			CDisplayObj *pDisplayObj=(*iter)->GetDisplayObjByLayerID(pDeviceDisplayObj->GetLayerId());
			if(!pDisplayObj || !pDisplayObj->IsICircuitDisObj())
				continue;

			CICircuit *pCircuit=(CICircuit *)*iter;
			CICircuitDisObj *pCircuitDisplayObj=(CICircuitDisObj *)pDisplayObj;

			double origin_box_width = pCircuit->GetBoxMaxX() - pCircuit->GetBoxMinX();
			double origin_box_height = pCircuit->GetBoxMaxY() - pCircuit->GetBoxMinY();

			double boxLeft, boxBottom, boxRight, boxTop;
			pCircuitDisplayObj->GetBox(boxLeft, boxBottom, boxRight, boxTop);
			double box_width = boxRight - boxLeft;
			double box_height = boxTop - boxBottom;
			double center_x = 0.5*(boxLeft + boxRight);
			double center_y = 0.5*(boxBottom + boxTop);

			//比例缩放到设备边框大小
			double x_scale = box_width/origin_box_width;
			double y_scale = box_height/origin_box_height;
			if (pCircuitDisplayObj->IsXYRatio())
			{
				x_scale = min(x_scale, y_scale); 
				y_scale=x_scale; //等宽高比缩放
			}

			IAcadBlock *pBlock=NULL;					
			if (pCircuit->IsCircuitPic())
			{
				COleSafeArray   safeOleArr;
				double   dValues[3]={boxLeft, boxBottom, 0};       
				safeOleArr.CreateOneDim(VT_R8,3,dValues);        
				VARIANT *pInsertPtVariant   =   (LPVARIANT)safeOleArr;
				CString strBlockName;
				strBlockName.Format(_T("%s_%d_%d"), pCircuit->GetName(), (long)pCircuit, pDeviceDisplayObj->GetLayerId());

				IAcadBlockReference *pBlockRef=NULL;
				m_pModelSpace->InsertBlock(*pInsertPtVariant, _bstr_t(strBlockName), x_scale, y_scale, 1, 0, vtMissing, &pBlockRef);
				pBlockRef->Release();
			}					
			if(!pCircuit->IsCircuitPic())
				//else
			{
				COleSafeArray   safeOleArr;
				double   dValues[3]={center_x, center_y, 0};       
				safeOleArr.CreateOneDim(VT_R8,3,dValues);        
				VARIANT *pInsertPtVariant=(LPVARIANT)safeOleArr;
				CString strBlockName;
				strBlockName.Format(_T("%s_%d_%d"), pCircuit->GetName(), (long)pCircuit, pDeviceDisplayObj->GetLayerId());				
				IAcadBlockReference *pBlockRef=NULL;				
				m_pModelSpace->InsertBlock(*pInsertPtVariant, _bstr_t(strBlockName), x_scale, y_scale, 1, 0, vtMissing, &pBlockRef);
				if (pBlockRef)
				{
					pBlockRef->Release();
				}						
			}

		}
	}
	//输出设备外形图
	if(!pDeviceDisplayObj->GetPicName().IsEmpty()/* && CircuitList.empty()*/)
	{
		double insert_pts[]={dblCenterX-dblHalfWidth, dblCenterY-dblHalfHeight/*+dblTileHeight*/, 0};

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPt =  (LPVARIANT)saInsertPts;

		CString strPicFile(pDeviceDisplayObj->GetPicName());
		//int nIndex=strPicFile.Find(_T(':'));
		//if(nIndex!=-1 && nIndex>1)
		//	strPicFile=strPicFile.Mid(nIndex-1);
		//CFile f;
		//f.Open(strPicFile, )
		CImageProp *pImageProp=pDeviceDisplayObj->GetEntityObj()->GetBigDrawing()->GetImageProp(strPicFile);
		if(pImageProp)
		{
			int nIndex=strPicFile.ReverseFind(_T('\\'));
			if(nIndex!=-1 && nIndex+1<strPicFile.GetLength())
			{
				CString strNewPicFile=strPicFile.Mid(nIndex+1);
				CString strExportDir = CModelObjOption::GetExportPicPath();
				if (strExportDir.ReverseFind(_T('\\')) != strExportDir.GetLength() - 1)
				{
					strExportDir = strExportDir + _T("\\");
				}
				strNewPicFile=strExportDir+strNewPicFile;
				pImageProp->Save(strNewPicFile);

				IAcadRasterImage *pImage=NULL;
				m_pModelSpace->AddRaster(_bstr_t(strNewPicFile), *pvInsertPt, 1.0, 0, &pImage);
				if(pImage)
				{
					pImage->put_ImageWidth(pDeviceDisplayObj->GetWidth());
					pImage->put_ImageHeight(pDeviceDisplayObj->GetHeight()-dblTileHeight);

					pImage->Release();
				}
			}
		}
	}

	//设备已没有单独的文字显示对象，挂起 by liuq2014.06.25
	//CTextDisplayObj *pTextDisplayObj=pDeviceDisplayObj->GetTextDisObj();
	//if(pTextDisplayObj && pTextDisplayObj->IsVisible())
	//{
	//	double dblTextHeight=pTextDisplayObj->GetTextSize();
	//	//dblTextHeight/=CTextDisplayObj::GetThreshold();
	//	dblCenterX=pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX();
	//	dblCenterY=pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY()-0.7*dblTextHeight;

	//	double insert_pts[]={dblCenterX-2.5*dblHalfWidth, dblCenterY+1.2*dblTextHeight, 0};
	//	COleSafeArray   saInsertPts;
	//	saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
	//	VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
	//	IAcadMText *pMText=NULL;
	//	m_pModelSpace->AddMText(*pvInsertPts, 5*dblHalfWidth, _bstr_t(pDevice->GetName()), &pMText);  //加宽防止文字过长，出现多行现象
	//	if(pMText)
	//	{
	//		IAcadAcCmColor *pColor=GetColor();
	//		if(pColor)
	//		{
	//			if(pTextDisplayObj)
	//				pColor->SetRGB((long)(pTextDisplayObj->GetTextColorR()*255), (long)(pTextDisplayObj->GetTextColorG()*255), (long)(pTextDisplayObj->GetTextColorB()*255));
	//			else
	//				pColor->SetRGB((long)(pDeviceDisplayObj->GetTextColorR()*255), (long)(pDeviceDisplayObj->GetTextColorG()*255), (long)(pDeviceDisplayObj->GetTextColorB()*255));
	//			pMText->put_TrueColor(pColor);
	//			pColor->Release();
	//		}
	//		pMText->put_Height(dblTextHeight);
	//		pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);

	//		CString strTextFont=pDeviceDisplayObj->GetTextFont();
	//		if(pTextDisplayObj)
	//			strTextFont=pTextDisplayObj->GetTextFont();
	//		CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
	//		if(!strTextStyle.IsEmpty())
	//			pMText->put_StyleName(_bstr_t(strTextStyle));
	//		pMText->Release();
	//	}

	//	dblTextHeight=0.8*dblTextHeight;
	//	insert_pts[1]=dblCenterY-0.2*dblTextHeight;
	//	saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
	//	pvInsertPts =  (LPVARIANT)saInsertPts;
	//	pMText=NULL;
	//	m_pModelSpace->AddMText(*pvInsertPts, 5*dblHalfWidth, _bstr_t(CString("(")+pDevice->GetNo()+_T(")")), &pMText);
	//	if(pMText)
	//	{
	//		IAcadAcCmColor *pColor=GetColor();
	//		if(pColor)
	//		{
	//			pColor->SetRGB((long)(pDeviceDisplayObj->GetTextColorR()*255), (long)(pDeviceDisplayObj->GetTextColorG()*255), (long)(pDeviceDisplayObj->GetTextColorB()*255));
	//			pMText->put_TrueColor(pColor);
	//			pColor->Release();
	//		}
	//		pMText->put_Height(dblTextHeight);
	//		pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
	//		CString strTextFont=pDeviceDisplayObj->GetTextFont();
	//		if(pTextDisplayObj)
	//			strTextFont=pTextDisplayObj->GetTextFont();
	//		CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
	//		if(!strTextStyle.IsEmpty())
	//			pMText->put_StyleName(_bstr_t(strTextStyle));
	//		pMText->Release();
	//	}
	//}

	//	pPolyline->Release();//在作为HATCH的边界时，Release后出错
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportConnector(IAcadModelSpace *pModelSpace, const CConnectorDisplayObj *pConnectorDisplayObj) const
{
	double dblCenterX=pConnectorDisplayObj->GetPosX();
	double dblCenterY=pConnectorDisplayObj->GetPosY();
	double dblHalfHeight=pConnectorDisplayObj->GetConnectorWidth()*0.5;
	double dblHalfLength=pConnectorDisplayObj->GetLength()*0.5;
	eConnectorSideType st=pConnectorDisplayObj->GetSideType();
	if(st==CONNECTOR_IN_LEFT_OF_PARENT)
	{
		dblCenterX-=dblHalfHeight;
		std::swap(dblHalfLength, dblHalfHeight);
	}
	else if(st==CONNECTOR_IN_RIGHT_OF_PARENT)
	{
		dblCenterX+=dblHalfHeight;
		std::swap(dblHalfLength, dblHalfHeight);
	}
	else if(st==CONNECTOR_IN_UP_OF_PARENT)
		dblCenterY+=dblHalfHeight;
	else if(st==CONNECTOR_IN_DOWN_OF_PARENT)
		dblCenterY-=dblHalfHeight;
	double pts[]={	dblCenterX-dblHalfLength, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfLength, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfLength, dblCenterY+dblHalfHeight, 0,
		dblCenterX-dblHalfLength, dblCenterY+dblHalfHeight, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 12, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	if(!pModelSpace)
		return false;
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_TRUE);
	//pPolyline->put_ConstantWidth(0.25);
	if (!pPolyline)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pConnectorDisplayObj->GetColorR()*255), (long)(pConnectorDisplayObj->GetColorG()*255), (long)(pConnectorDisplayObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pConnectorDisplayObj->GetFillColorR()*255), (long)(pConnectorDisplayObj->GetFillColorG()*255), (long)(pConnectorDisplayObj->GetFillColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}

		COleSafeArray saLoop;
		//IDispatch * ent_array[]={pPolyline};
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
		VARIANT * pvLoop=(LPVARIANT)saLoop;

		pHatch->AppendOuterLoop(*pvLoop);


		pHatch->Release();
	}
	//接插件没有单独的文字显示对象，挂起 by liuq2014.06.25
	//CTextDisplayObj *pTextDisplayObj=pConnectorDisplayObj->GetTextDisObj();
	//if(pTextDisplayObj && pTextDisplayObj->IsVisible())
	{
		double dblTextHeight=pConnectorDisplayObj->GetTextSize();
		//dblTextHeight/=CTextDisplayObj::GetThreshold();
		double insert_pts[]={dblCenterX-/*10*/1*dblHalfLength, dblCenterY+0.5*dblTextHeight, 0};
		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		CConnector *pConnector=(CConnector *)pConnectorDisplayObj->GetEntityObj();
		IAcadMText *pMText=NULL;
		CString strCode=pConnectorDisplayObj->GetShowName();
		m_pModelSpace->AddMText(*pvInsertPts, /*20*/2*dblHalfLength, _bstr_t(strCode), &pMText);
		if(pMText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pConnectorDisplayObj->GetTextColorR()*255), (long)(pConnectorDisplayObj->GetTextColorG()*255), (long)(pConnectorDisplayObj->GetTextColorB()*255));
				pMText->put_TrueColor(pColor);
				pColor->Release();
			}
			pMText->put_Height(dblTextHeight);
			pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
			if(st==CONNECTOR_IN_LEFT_OF_PARENT || st==CONNECTOR_IN_RIGHT_OF_PARENT)
			{
				pMText->put_Rotation(PI*0.5);
				pMText->put_DrawingDirection(AutoCAD::acBottomToTop);
			}

			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pConnectorDisplayObj->GetTextFont());
			if(!strTextStyle.IsEmpty())
				pMText->put_StyleName(_bstr_t(strTextStyle));
			pMText->Release();
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportPin(IAcadModelSpace *pModelSpace, const CPinDisplayObj *pPinDisplayObj) const
{
	double dblPosX=pPinDisplayObj->GetPosX();
	double dblPosY=pPinDisplayObj->GetPosY();

	double dblEndX,dblEndY;
	((CPinDisplayObj *)pPinDisplayObj)->GetEndPosWithoutCircle(dblEndX, dblEndY);
	eConnectorSideType eType;
	bool bGetType = ((CPinDisplayObj *)pPinDisplayObj)->GetConnectorSideType(eType);
	if (!bGetType)
		return true ;
	double pts[]={	dblPosX, dblPosY, 0,
		dblEndX, dblEndY, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 6, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	if(!pModelSpace)
		return false;
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	//pPolyline->put_ConstantWidth(0.25);
	if (!pPolyline)
		return false;

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pPinDisplayObj->GetColorR()*255), (long)(pPinDisplayObj->GetColorG()*255), (long)(pPinDisplayObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	pPolyline->Release();

	// 	double dblCenterX,dblCenterY;
	// 	double dblRadius=((CPinDisplayObj *)pPinDisplayObj)->GetPinCircleRadius();
	// 	double g_iPinLength =pPinDisplayObj->GetPinLength();
	// 	switch (eType)
	// 	{
	// 	case CONNECTOR_IN_LEFT_OF_PARENT:
	// 		dblCenterX = dblEndX - dblRadius;
	// 		dblCenterY = dblEndY;
	// 		break;
	// 
	// 	case CONNECTOR_IN_DOWN_OF_PARENT:
	// 		dblCenterX = dblEndX;
	// 		dblCenterY = dblEndY-dblRadius;
	// 		break;
	// 
	// 	case CONNECTOR_IN_RIGHT_OF_PARENT:
	// 		dblCenterX = dblEndX + dblRadius;
	// 		dblCenterY = dblEndY;
	// 		break;
	// 
	// 	case CONNECTOR_IN_UP_OF_PARENT:
	// 		dblCenterX = dblEndX;
	// 		dblCenterY = dblEndY + dblRadius;
	// 		break;
	// 
	// 	default:
	// 		break;
	// 	}
	// 	
	// 	COleSafeArray   safeOleArr;
	// 	double   dValues[3]={dblCenterX, dblCenterY, 0};       
	// 	safeOleArr.CreateOneDim(VT_R8,3,dValues);        
	// 	VARIANT   *   pNewPointVariant   =   (LPVARIANT)safeOleArr;     
	// 	IAcadCircle *pCircle=NULL;
	// 	m_pModelSpace->AddCircle(*pNewPointVariant, dblRadius, &pCircle);
	// 
	// 	pColor=GetColor();
	// 	if(pColor)
	// 	{
	// 		pColor->SetRGB((long)(pPinDisplayObj->GetColorR()*255), (long)(pPinDisplayObj->GetColorG()*255), (long)(pPinDisplayObj->GetColorB()*255));
	// 		pCircle->put_TrueColor(pColor);
	// 		pColor->Release();
	// 	}

	// 	IAcadHatch *pHatch=NULL;
	// 	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	// 	if(pHatch)
	// 	{
	// 		IAcadAcCmColor *pColor=GetColor();
	// 		if(pColor)
	// 		{
	// 			pColor->SetRGB((long)(pPinDisplayObj->GetFillColorR()*255), (long)(pPinDisplayObj->GetFillColorG()*255), (long)(pPinDisplayObj->GetFillColorB()*255));
	// 			pHatch->put_TrueColor(pColor);
	// 			pColor->Release();
	// 		}
	// 
	// 		COleSafeArray saLoop;
	// 		//IDispatch * ent_array[]={pPolyline};
	// 		saLoop.CreateOneDim(VT_DISPATCH, 1, &pCircle);
	// 		VARIANT * pvLoop=(LPVARIANT)saLoop;
	// 
	// 		pHatch->AppendOuterLoop(*pvLoop);
	// 
	// 		pHatch->Release();
	// 	}

	// 	pCircle->Release();
	//管脚没有单独的文字显示对象，挂起 by liuq2014.06.25
	//CTextDisplayObj *pTextDisplayObj=pPinDisplayObj->GetTextDisObj();
	//if(pTextDisplayObj && pTextDisplayObj->IsVisible())
	CLayerProperty* pLayerProp=pPinDisplayObj->GetLayerProperty();
	if (!pLayerProp->IsDisablePinText())
	{
		double dblTextHeight=pPinDisplayObj->GetTextSize();
		//dblTextHeight/=CTextDisplayObj::GetThreshold();
		double g_iPinLength = pPinDisplayObj->GetPinLength();		
		double dbTextX = 0.0, dbTextY = 0.0;
		eConnectorSideType eType;
		bool bGetType = ((CPinDisplayObj *)pPinDisplayObj)->GetConnectorSideType(eType);
		if (bGetType)
		{
			if(eType==CONNECTOR_IN_LEFT_OF_PARENT)
			{
				dbTextX = dblEndX + dblTextHeight * 0.5;
				dbTextY = dblEndY ;
			}
			else if(eType==CONNECTOR_IN_RIGHT_OF_PARENT)
			{
				dbTextX = dblEndX - dblTextHeight * 0.5;
				dbTextY = dblEndY ;

			}
			else if(eType==CONNECTOR_IN_UP_OF_PARENT)
			{
				dbTextX = dblEndX ;
				dbTextY = dblEndY - dblTextHeight * 0.5;
			}
			else if(eType==CONNECTOR_IN_DOWN_OF_PARENT)
			{
				dbTextX = dblEndX ;
				dbTextY = dblEndY + dblTextHeight * 0.5;
			}

		}
		double insert_pts[]={dbTextX, dbTextY, 0};
		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		CPin *pPin=(CPin *)pPinDisplayObj->GetEntityObj();
		IAcadText *pText=NULL;
		CString szPinName(_T(""));
		if ( pPinDisplayObj->GetAliasName() != _T("") )
			szPinName = pPinDisplayObj->ReCalcAliasName(pPinDisplayObj->GetAliasName());
		else 
			szPinName = pPin->GetName();
		m_pModelSpace->AddText(bstr_t(szPinName), *pvInsertPts, dblTextHeight, &pText);
		if(pText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pPinDisplayObj->GetTextColorR()*255), (long)(pPinDisplayObj->GetTextColorG()*255), (long)(pPinDisplayObj->GetTextColorB()*255));
				pText->put_TrueColor(pColor);
				pColor->Release();
			}
			if (bGetType)
			{
				if(eType==CONNECTOR_IN_LEFT_OF_PARENT)
				{
					pText->put_Alignment(AutoCAD::acAlignmentRight);	
				}
				else if(eType==CONNECTOR_IN_RIGHT_OF_PARENT)
				{
					pText->put_Alignment(AutoCAD::acAlignmentLeft);
				}
				else if(eType==CONNECTOR_IN_UP_OF_PARENT)
				{
					pText->put_Alignment(AutoCAD::acAlignmentLeft );
					pText->put_Rotation(PI*0.5);
				}
				else if(eType==CONNECTOR_IN_DOWN_OF_PARENT)
				{
					pText->put_Alignment(AutoCAD::acAlignmentRight);
					pText->put_Rotation(PI*0.5);
				}
				pText->put_TextAlignmentPoint(*pvInsertPts);
			}

			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pPinDisplayObj->GetTextFont());
			if(!strTextStyle.IsEmpty())
				pText->put_StyleName(_bstr_t(strTextStyle));
			pText->Release();
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSubCableText(IAcadModelSpace *pModelSpace, CSubCableDisplayObj *pSubCableDis,int nSegIndex,CTextDisplayObj*pTextDisplayObj,CString strCableNo) const
{
	double dblTextHeight=pTextDisplayObj->GetTextSize();

	double wireSegLength=pSubCableDis->getSegLength(nSegIndex);
	double textLenth=pTextDisplayObj->GetTextLength();
	double m_textDis=pSubCableDis->GetWireTextDistance();
	if(m_textDis<0)
		m_textDis=CModelObjOption::GetWireTextDistance();
	double x=0;
	double y=0;
	if (pTextDisplayObj->IsHorizon())
	{
		x = pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX();
		y = pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY();			
	}
	else
	{
		x = pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX();
		y = pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY();
	}

	double insert_pts[]={x, y, 0};

	COleSafeArray   saInsertPts;
	saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
	VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
	IAcadText *pText=NULL;
	if(!pModelSpace)
		return false;
	m_pModelSpace->AddText(bstr_t(strCableNo), *pvInsertPts, dblTextHeight*0.85, &pText);
	if(pText)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			if(pTextDisplayObj)
				pColor->SetRGB((long)(pTextDisplayObj->GetTextColorR()*255), (long)(pTextDisplayObj->GetTextColorG()*255), (long)(pTextDisplayObj->GetTextColorB()*255));
			else
				pColor->SetRGB((long)(pSubCableDis->GetTextColorR()*255), (long)(pSubCableDis->GetTextColorG()*255), (long)(pSubCableDis->GetTextColorB()*255));
			pText->put_TrueColor(pColor);
			pColor->Release();
		}

		if (pTextDisplayObj->IsHorizon())
		{
			pText->put_Alignment(AutoCAD::acAlignmentMiddle);
			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		else
		{
			pText->put_Alignment(AutoCAD::acAlignmentMiddle);
			pText->put_TextAlignmentPoint(*pvInsertPts);
			pText->put_Rotation(PI*0.5);
		}

		CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pSubCableDis->GetTextFont());
		if(!strTextStyle.IsEmpty())
			pText->put_StyleName(_bstr_t(strTextStyle));
		pText->Release();
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSubCable(IAcadModelSpace *pModelSpace, CSubCableDisplayObj *pSubCableDis) const
{
	list<pair<double, double> > & SegList=pSubCableDis->GetMidPtList();
	if(SegList.empty())
		return true;

	long lPtSize=SegList.size();
	double * pts=new double[lPtSize*3];

	list<pair<double, double> >::const_iterator iter=SegList.begin();
	list<pair<double, double> >::const_iterator it_next=iter;
	++it_next;

	pts[0]=iter->first;
	pts[1]=iter->second;
	pts[2]=0;
	int i=1;
	int index =0;
	if(!pModelSpace)
		return false;
	for(; it_next!=SegList.end(); ++iter, ++it_next,++index)
	{
		pts[3*i]=it_next->first;
		pts[3*i+1]=it_next->second;
		pts[3*i+2]=0;
		bool bRet = true;
		list<pair<CTextDisplayObj*, CTextDisplayObj*> > lstTextDis;
		pSubCableDis->GetSegTextAndLengthList(index,lstTextDis);
		if(lstTextDis.size()>0)
		{
			list<pair<CTextDisplayObj*, CTextDisplayObj*> >::iterator iter_text=lstTextDis.begin();
			for(int j=0;iter_text!=lstTextDis.end();iter_text++,j++)
			{
				CTextDisplayObj* pTextDisplayObj=iter_text->first;
				CTextDisplayObj* pLenghtDis=iter_text->second;
				if (pTextDisplayObj&&pTextDisplayObj->IsShowThis())
				{
					CString strCableNo = pSubCableDis->GetTextName(false,index);
					bRet = ExportSubCableText(m_pModelSpace,pSubCableDis,index,pTextDisplayObj,strCableNo);
					if (!bRet)
						return false;
				}
				if (pLenghtDis&&pLenghtDis->IsShowThis())
				{
					CString strCableNo = pSubCableDis->GetTextName(true,index);
					bRet = ExportSubCableText(m_pModelSpace,pSubCableDis,index,pLenghtDis,strCableNo);
					if (!bRet)
						return false;
				}
			}
		}
		i++;
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, lPtSize*3, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	if(!pModelSpace)
		return false;
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	if(pSubCableDis->GetLineWidth()>1.0001)
		pPolyline->put_ConstantWidth(pSubCableDis->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pSubCableDis->GetColorR()*255), (long)(pSubCableDis->GetColorG()*255), (long)(pSubCableDis->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	pPolyline->Release();

	delete []pts;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportWire(IAcadModelSpace *pModelSpace, CWireDisplayObj *pWireDisplayObj) const
{  //0717;
	if (pWireDisplayObj == NULL)
	{
		return true;
	}
	const std::list<std::pair<std::pair<double, double>, std::list<CTextDisplayObj *>> > & SegList=pWireDisplayObj->GetMidSegList();
	if(SegList.empty())
		return true;

	long lPtSize=SegList.size();
	double * pts=new double[lPtSize*3];

	std::list<std::pair<std::pair<double, double>, std::list<CTextDisplayObj *>> >::const_iterator iter=SegList.begin();
	std::list<std::pair<std::pair<double, double>,std::list<CTextDisplayObj *>> >::const_iterator it_next=iter;
	++it_next;

	pts[0]=iter->first.first;
	pts[1]=iter->first.second;
	pts[2]=0;
	CLayerProperty* pLayerProp = pWireDisplayObj->GetLayerProperty();
	int i=1;
	int index =0;
	for(; it_next!=SegList.end(); ++iter, ++it_next,++index)
	{
		pts[3*i]=it_next->first.first;
		pts[3*i+1]=it_next->first.second;
		pts[3*i+2]=0;
		i++;
		if (pLayerProp && pLayerProp->IsDisableText())
		{
			continue;
		}
		//luoqy::2014-7-3
		std::list<CTextDisplayObj *> pTmpTextDisList = (*it_next).second;
		if(pTmpTextDisList.size()>0)
		{
			std::list<CTextDisplayObj*>::iterator iter_textDisObj=pTmpTextDisList.begin();
			for(int j=0;iter_textDisObj!=pTmpTextDisList.end();iter_textDisObj++,j++)
			{
				CTextDisplayObj* pTextDisplayObj=*iter_textDisObj;
				if (pTextDisplayObj&&pTextDisplayObj->IsShowThis())
				{
					CString strCableNo = ((CWireDisplayObj*)pWireDisplayObj)->GetTextName();
					double dblTextHeight=pTextDisplayObj->GetTextSize();
					//CSystem *pSystem=pWireDisplayObj->GetEntityObj()->GetBigDrawing();
					//if(pSystem)
					//{
					//	CSystemAttribute *pSysAttr=pSystem->GetSysAttribute();
					//	dblTextHeight=pSysAttr->GetConnecterWidth();
					//}

					//double dblTextOffset=dblTextHeight;

					double wireSegLength=pWireDisplayObj->getSegLength(index);
					double textLenth=pTextDisplayObj->GetTextLength();
					double m_textDis=pWireDisplayObj->GetWireTextDistance();
					if(m_textDis<0)
						m_textDis=CModelObjOption::GetWireTextDistance();
					double x=0;
					double y=0;
					if (pTextDisplayObj->IsHorizon())
					{
						x = pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX();
						y = pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY();			
					}
					else
					{
						x = pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX();
						y = pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY();
					}

					double insert_pts[]={x, y, 0};

					//double insert_pts[]={pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX(), pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY(), 0};
					//if(pTextDisplayObj->IsHorizon())
					//	insert_pts[1]+=dblTextOffset;
					//else
					//	insert_pts[0]+=dblTextOffset;

					COleSafeArray   saInsertPts;
					saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
					VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
					IAcadText *pText=NULL;
					if(!pModelSpace)
						return false;
					m_pModelSpace->AddText(bstr_t(strCableNo), *pvInsertPts, dblTextHeight, &pText);
					if(pText)
					{
						IAcadAcCmColor *pColor=GetColor();
						if(pColor)
						{
							if(pTextDisplayObj)
								pColor->SetRGB((long)(pTextDisplayObj->GetTextColorR()*255), (long)(pTextDisplayObj->GetTextColorG()*255), (long)(pTextDisplayObj->GetTextColorB()*255));
							else
								pColor->SetRGB((long)(pWireDisplayObj->GetTextColorR()*255), (long)(pWireDisplayObj->GetTextColorG()*255), (long)(pWireDisplayObj->GetTextColorB()*255));
							pText->put_TrueColor(pColor);
							pColor->Release();
						}

						if (pTextDisplayObj->IsHorizon())
						{
							pText->put_Alignment(AutoCAD::acAlignmentMiddle);
							pText->put_TextAlignmentPoint(*pvInsertPts);
						}
						else
						{
							pText->put_Alignment(AutoCAD::acAlignmentMiddle);
							pText->put_TextAlignmentPoint(*pvInsertPts);
							pText->put_Rotation(PI*0.5);
						}

						CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pWireDisplayObj->GetTextFont());
						if(!strTextStyle.IsEmpty())
							pText->put_StyleName(_bstr_t(strTextStyle));
						pText->Release();
					}
				}
			}
		}
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, lPtSize*3, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	if(!pModelSpace)
		return false;
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	if (!pPolyline)
		return false;
	if(pWireDisplayObj->GetLineWidth()>1.0001)
		pPolyline->put_ConstantWidth(pWireDisplayObj->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pWireDisplayObj->GetColorR()*255), (long)(pWireDisplayObj->GetColorG()*255), (long)(pWireDisplayObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	eLinePattern lp=pWireDisplayObj->GetLinePattern();
	if(lp==DASH_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDEN")))
			pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
		//IAcadLineType *pLineType=NULL;
		//pLineTypes->Add(_bstr_t(""), &pLineType);

		//pLineType->get_Description()
		pPolyline->put_Linetype(_bstr_t("HIDDEN"));
		//pPolyline->put_LinetypeScale(0.1);
	}
	else if(lp==DOTTED_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DOT")))
			pLineTypes->Load(_bstr_t("DOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DOT"));
	}
	else if(lp==DASH_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DASHDOT")))
			pLineTypes->Load(_bstr_t("DASHDOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DASHDOT"));
	}
	else if(lp==DASH_DOUBLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DIVIDE")))
			pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DIVIDE"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("ACAD_ISO14W100")))
			pLineTypes->Load(_bstr_t("ACAD_ISO14W100"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("ACAD_ISO14W100"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDENX2")))
			pLineTypes->Load(_bstr_t("HIDDENX2"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("HIDDENX2"));
	}
	else if(lp==CENTER_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("CENTER")))
			pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("CENTER"));
	}
	else if(lp==PHANTOM_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("PHANTOM")))
			pLineTypes->Load(_bstr_t("PHANTOM"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("PHANTOM"));
	}

	pPolyline->Release();

	delete []pts;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitAsBlockDef(IAcadBlocks *pBlockDefs, CSubSystem *pSystem, long lLayerId, CExportProgressDlg *pProgressDlg)
{
	if (IsStopLayerExport())
	{
		return false;
	}
	const std::list<CDevice *> & DeviceList=pSystem->GetDeviceList();
	std::list<CDevice *>::const_iterator it_device;
	for(it_device=DeviceList.begin(); it_device!=DeviceList.end(); ++it_device)
	{
		bool bRet = ExportCircuitAsBlockDef(pBlockDefs, *it_device, lLayerId, pProgressDlg);
		if (!bRet)
			return false;
	}


	const std::list<CSubSystem *> & SubSystemList=pSystem->GetSubSystemList();
	std::list<CSubSystem *>::const_iterator it_ss;
	for(it_ss=SubSystemList.begin(); it_ss!=SubSystemList.end(); ++it_ss)
	{
		bool bRet = ExportCircuitAsBlockDef(pBlockDefs, *it_ss, lLayerId, pProgressDlg);   
		if(!bRet)
			return false;
	}
	return true;	
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitAsBlockDef(IAcadBlocks *pBlockDefs, CDevice *pDevice, long lLayerId, CExportProgressDlg *pProgressDlg)
{
	if (IsStopLayerExport())
	{
		return false;
	}
	std::map<CString,CEntityObj*> mapCircuitDrawingList = pDevice->GetCircuitFile2EntMap();
	std::map<CString,CEntityObj*>::iterator iter = mapCircuitDrawingList.begin();
	for (;iter!=mapCircuitDrawingList.end();iter++)
	{
		if(!iter->second->IsICircuit())
			continue;

		CICircuit *pICircuit=(CICircuit*)iter->second;

		CDisplayObj *pDisplayObj=pICircuit->GetDisplayObjByLayerID(lLayerId);
		if(pDisplayObj)
		{
			//生成块定义
			CString szTxt=_T("正在导出接口电路：")+pICircuit->GetName();
			ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

			if (pICircuit->IsCircuitPic())
			{
				//图片的插入点是左下角
				IAcadBlock *pBlock=NULL;
				COleSafeArray   safeOleArr;
				double   dValues[3]={pICircuit->GetBoxMinX(), pICircuit->GetBoxMinY(), 0};       
				safeOleArr.CreateOneDim(VT_R8,3,dValues);        
				VARIANT *pInsertPtVariant   =   (LPVARIANT)safeOleArr;
				CString strBlockName;
				strBlockName.Format(_T("%s_%d_%d"), pICircuit->GetName(), (long)pICircuit, lLayerId);
				pBlockDefs->Add(*pInsertPtVariant, _bstr_t(strBlockName), &pBlock);

				CString strPicFile = iter->first;
				//先将图片保存到输出目录
				CImageProp *pImageProp=pDevice->GetBigDrawing()->GetImageProp(strPicFile);
				if(pImageProp)
				{
					int nIndex=strPicFile.ReverseFind(_T('\\'));
					if(nIndex!=-1 && nIndex+1<strPicFile.GetLength())
					{
						CString strNewPicFile=strPicFile.Mid(nIndex+1);
						//strNewPicFile=CModelObjOption::GetExportPicPath() + _T("\\") + strNewPicFile;		//少“\\”
						CString strExportDir = CModelObjOption::GetExportPicPath();
						if (strExportDir.ReverseFind(_T('\\')) != strExportDir.GetLength() - 1)
						{
							strExportDir = strExportDir + _T("\\");
						}
						strNewPicFile=strExportDir+strNewPicFile;
						pImageProp->Save(strNewPicFile);

						IAcadRasterImage *pImage=NULL;
						pBlock->AddRaster(_bstr_t(strNewPicFile),*pInsertPtVariant,1.0,0,&pImage);
						if(pImage)
						{
							pImage->put_ImageWidth(pICircuit->GetBoxMaxX() - pICircuit->GetBoxMinX());
							pImage->put_ImageHeight(pICircuit->GetBoxMaxY()- pICircuit->GetBoxMinY());
							pImage->Release();
						}
					}
				}
				long pts_size=12;
				double pts[]={
					pICircuit->GetBoxMinX(), pICircuit->GetBoxMinY(), 0,
					pICircuit->GetBoxMinX(), pICircuit->GetBoxMaxY(), 0,
					pICircuit->GetBoxMaxX(), pICircuit->GetBoxMaxY(), 0,
					pICircuit->GetBoxMaxX(), pICircuit->GetBoxMinY(), 0};

					COleSafeArray   saPts;
					saPts.CreateOneDim(VT_R8, pts_size, pts);        
					VARIANT * pvPts =  (LPVARIANT)saPts;     

					IAcadPolyline *pPolyline=NULL;
					pBlock->AddPolyline(*pvPts, &pPolyline);
					pPolyline->put_Closed(VARIANT_TRUE);
					pPolyline->put_LinetypeScale(0.01);

					IAcadAcCmColor *pColor=GetColor();
					if(pColor)
					{
						pColor->SetRGB((long)(128), (long)(128), (long)(128));
						pPolyline->put_TrueColor(pColor);
						pColor->Release();
					}

					IAcadDatabase *pDatabase=NULL;
					pBlock->get_Database(&pDatabase);

					IAcadLineTypes *pLineTypes=NULL;
					pDatabase->get_Linetypes(&pLineTypes);

					if(!ExistLineType(pLineTypes, _T("CENTER")))
						pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
					pPolyline->put_Linetype(_bstr_t("CENTER"));
					pPolyline->Update();

					pPolyline->Release();
					pBlock->Release();
			}
			else
			{
				double origin_box_centerX = 0.5*(pICircuit->GetBoxMinX() + pICircuit->GetBoxMaxX());
				double origin_box_centerY = 0.5*(pICircuit->GetBoxMinY() + pICircuit->GetBoxMaxY());

				IAcadBlock *pBlock=NULL;
				COleSafeArray   safeOleArr;
				double   dValues[3]={origin_box_centerX, origin_box_centerY, 0};       
				safeOleArr.CreateOneDim(VT_R8,3,dValues);        
				VARIANT *pInsertPtVariant   =   (LPVARIANT)safeOleArr;
				CString strBlockName;
				strBlockName.Format(_T("%s_%d_%d"), pICircuit->GetName(), (long)pICircuit, lLayerId);
				pBlockDefs->Add(*pInsertPtVariant, _bstr_t(strBlockName), &pBlock);
				ExportCircuitAsBlockDef(pBlock, pICircuit, lLayerId);
				pBlock->Release();
			}
		}
	}	
	return true;	
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitAsBlockDef(IAcadBlock *pBlockDef, CICircuit *pICircuit, long lLayerId)
{	
	if (IsStopLayerExport())
	{
		return false;
	}
	bool bRet = true;
	std::list<CCircuitUnit *> CircuitUnitList=pICircuit->GetCircuitUnitList();
	std::list<CCircuitUnit *>::iterator iter;
	for(iter=CircuitUnitList.begin(); iter!=CircuitUnitList.end(); ++iter)
	{
		eCircuitUnitEntType  ct=(*iter)->GetUnitType();
		if(ct==CIRCUIT_PART)
			bRet = ExportCircuitUnitPart(pBlockDef, (CCircuitPart *)*iter, lLayerId);
		else if(ct==ALTIUM_CIRCUIT_PART)	//dsj 20190723
			bRet = ExportAltiumCircuitPart(pBlockDef, (CAltiumCircuitPart *)*iter, lLayerId);
		else if (ct == MENTOR_CIRCUIT_PART)	//dsj 20190724
			bRet = ExportMentorCircuitPart(pBlockDef, (MentorCircuitPart *)*iter, lLayerId);
		else if (ct==TINYCAD_CIRCUIT_PART)
			bRet = ExportDsnCircuitPart(pBlockDef, (DsnCircuitPart *)*iter, lLayerId);
		else if(ct==CIRCUIT_WIRE)
			bRet = ExportCircuitUnitWire(pBlockDef, (CCircuitWire *)*iter, lLayerId);
		else if(ct==CIRCUIT_BUS)
			bRet = ExportCircuitUnitBus(pBlockDef, (CCircuitBus *)*iter, lLayerId);
		else if(ct==CIRCUIT_PIN)
			bRet = ExportCircuitUnitPin(pBlockDef, (CCircuitPin *)*iter, lLayerId);
		else if(ct==CIRCUIT_PORT)
			bRet = ExportCircuitUnitPort(pBlockDef, (CCircuitPort *)*iter,lLayerId);
		else if(ct==CIRCUIT_ANNOTATION)
			bRet = ExportCircuitUnitAnnotation(pBlockDef, (CCircuitAnnotation *)*iter, lLayerId);
		else if(ct==CIRCUIT_ARC)
			bRet = ExportCircuitUnitArc(pBlockDef, (CCircuitArc *)*iter, lLayerId);
		else if(ct==CIRCUIT_LINE)
			bRet = ExportCircuitUnitLine(pBlockDef, (CCircuitLine *)*iter, lLayerId);
		else if(ct==CIRCUIT_POLYLINE)
			bRet = ExportCircuitUnitPolyline(pBlockDef, (CCircuitPolyline *)*iter, lLayerId);
		else if(ct==CIRCUIT_POLYGON)
			bRet = ExportCircuitUnitPolygon(pBlockDef, (CCircuitPolygon *)*iter, lLayerId);
		else if(ct==CIRCUIT_RECT)
			bRet = ExportCircuitUnitRect(pBlockDef, (CCircuitRectangle *)*iter, lLayerId);
		else if(ct==CIRCUIT_ELLIPSE)
			bRet = ExportCircuitUnitEllipse(pBlockDef, (CCircuitEllipse *)*iter, lLayerId);
		else if(ct==CIRCUIT_ELLIPSE_ARC)
			bRet = ExportCircuitUnitEllipseArc(pBlockDef, (CCircuitEllipseArc *)*iter, lLayerId);
		else if(ct==CIRCUIT_POWERPORT)
			bRet = ExportCircuitUnitPowerPort(pBlockDef, (CCircuitPowerPort *)*iter, lLayerId);
		else if(ct==CIRCUIT_BUSENTRY)
			bRet = ExportCircuitUnitBusEntry(pBlockDef, (CCircuitBusEntry *)*iter, lLayerId);
		else if(ct==CIRCUIT_JUNCTION)
			bRet = ExportCircuitUnitJunction(pBlockDef, (CCircuitJunction *)*iter, lLayerId);
		else if(ct==CIRCUIT_ROUNDRECT)
			bRet = ExportCircuitUnitRoundRect(pBlockDef, (CCircuitRoundRect *)*iter, lLayerId);
		else if(ct==CIRCUIT_TEXTFRAME)
			bRet = ExportCircuitUnitTextFrame(pBlockDef, (CCircuitTextFrame *)*iter, lLayerId);
		else if(ct==CIRCUIT_NETLABEL)
			bRet = ExportCircuitUnitNetLabel(pBlockDef, (CCircuitNetLabel *)*iter, lLayerId);
		else if(ct==CIRCUIT_NOERC)
			bRet = ExportCircuitUnitNoERC(pBlockDef, (CCircuitNoERC *)*iter, lLayerId);
		else if(ct==CIRCUIT_PROBE)
			bRet = ExportCircuitUnitSimProbe(pBlockDef, (CCircuitSimProbe *)*iter, lLayerId);
		else if(ct==CIRCUIT_STIMULUS)
			bRet = ExportCircuitUnitSimStimulus(pBlockDef, (CCircuitSimStimulus *)*iter, lLayerId);
		else if(ct==CIRCUIT_TEST_VECTOR)
			bRet = ExportCircuitUnitSimVector(pBlockDef, (CCircuitSimVector *)*iter, lLayerId);
		else if(ct==CIRCUIT_BEZIRE)
			bRet = ExportCircuitUnitBezier(pBlockDef, (CCircuitBezier *)*iter, lLayerId);
		else if(ct==CIRCUIT_GRAPHIC)
			bRet = ExportCircuitUnitGraphic(pBlockDef, (CCircuitGraph *)*iter, lLayerId);
		else if(ct==CIRCUIT_PIECHART)
			bRet = ExportCircuitUnitPieChart(pBlockDef, (CCircuitPieChart *)*iter, lLayerId);
		else if(ct==CIRCUIT_PCBLAYOUT)
			bRet = ExportCircuitUnitPCBLayoout(pBlockDef,(CCircuitLayoutDirective*)*iter,lLayerId);
		//else if(ct==CIRCUIT_SHEETSYMBOL)
		//	ExportCircuitUnit(pBlockDef, (CCircuitSheetSymbol *)*iter, lLayerId);
		//else if(ct==CIRCUIT_SHEETENTRY)
		//	ExportCircuitUnit(pBlockDef, (CCircuitSheetEntry *)*iter, lLayerId);
		//else if(ct==CIRCUIT_PROCCONTAINER)
		//	ExportCircuitUnit(pBlockDef, (CCircuit *)*iter, lLayerId);

		if (!bRet)
		{
			return false;
		}
	}

	/*long pts_size=12;
	double pts[]={
	pICircuit->GetBoxMinX(), pICircuit->GetBoxMinY(), 0,
	pICircuit->GetBoxMinX(), pICircuit->GetBoxMaxY(), 0,
	pICircuit->GetBoxMaxX(), pICircuit->GetBoxMaxY(), 0,
	pICircuit->GetBoxMaxX(), pICircuit->GetBoxMinY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
	return false;
	pPolyline->put_Closed(VARIANT_TRUE);
	pPolyline->put_LinetypeScale(0.01);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
	pColor->SetRGB((long)(128), (long)(128), (long)(128));
	pPolyline->put_TrueColor(pColor);
	pColor->Release();
	}

	IAcadDatabase *pDatabase=NULL;
	pBlockDef->get_Database(&pDatabase);
	if(!pDatabase)
	return false;
	IAcadLineTypes *pLineTypes=NULL;
	pDatabase->get_Linetypes(&pLineTypes);
	if(!pLineTypes)
	return false;
	if(!ExistLineType(pLineTypes, _T("CENTER")))
	pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
	pPolyline->put_Linetype(_bstr_t("CENTER"));
	pPolyline->Update();

	pPolyline->Release();  */ 
	return true;	
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPart(IAcadBlock *pBlockDef, CCircuitPart *pPart, long lLayerId)
{
	if (IsStopLayerExport())
		return false;
	//绘制组件名称
	CPartDesignator *pNameInfo = pPart->GetDesignator();
	if (pNameInfo && !pNameInfo->IsHide())
	{
		bool bRet =		ExportPartDesignator(pBlockDef, pNameInfo);
		if (!bRet)
			return false;		
	}

	//绘制组件值
	CPartDesignator *pValueInfo = pPart->GetTypeValue();
	if (pValueInfo && !pValueInfo->IsHide())
	{
		bool bRet =		ExportPartDesignator(pBlockDef, pValueInfo);
		if (!bRet)
			return false;
	}
	bool bIsMirrowed=pPart->IsMirrowed();
	double dblRotateAngle=pPart->GetRotateAngle();
	double dblTransX=pPart->GetPosX();
	double dblTransY=pPart->GetPosY();

	CTransform translate=CTransform::translate(dblTransX , dblTransY , 0);
	CTransform rotate=CTransform::rotate(dblRotateAngle*PI/180.0, 0, 0, 1);
	CTransform ts=rotate*translate;
	if(bIsMirrowed)
	{
		CTransform mirror=CTransform::MirrorByPlane(CVec(1.0, 0.0, 0.0));
		ts=mirror*ts;
	}
	double mat[16];
	ts.GetDataInColFirst(mat);

	std::list<CCircuitUnit *> lstSonUnits;
	ePartShowType type = pPart->GetShowType();
	switch (type)
	{
	case NORMAL_SHOW_TYPE:
		lstSonUnits = pPart->GetNormalUnitList();
		break;

	case DEMORGAN_SHOW_TYPE:
		lstSonUnits = pPart->GetDeMorganUnitList();
		break;

	case IEEE_SHOW_TYPE:
		lstSonUnits = pPart->GetIEEEUnitList();
		break;
	}
	bool bRet = true;
	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSonUnits.begin(); it_son!=lstSonUnits.end(); it_son++)
	{
		CCircuitUnit *pSonUnit = *it_son;
		CDisplayObj *pSonUnitDis = pSonUnit->GetDisplayObjByLayerID(lLayerId);
		if (pSonUnitDis)
		{
			eCircuitUnitEntType  ct=pSonUnit->GetUnitType();

			if(ct==CIRCUIT_ANNOTATION)
				bRet = ExportCircuitUnitAnnotation(pBlockDef, (CCircuitAnnotation *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIN)
				bRet = ExportCircuitUnitPin(pBlockDef, (CCircuitPin *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ARC)
				bRet = ExportCircuitUnitArc(pBlockDef, (CCircuitArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_LINE)
				bRet = ExportCircuitUnitLine(pBlockDef, (CCircuitLine *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYLINE)
				bRet = ExportCircuitUnitPolyline(pBlockDef, (CCircuitPolyline *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYGON)
				bRet = ExportCircuitUnitPolygon(pBlockDef, (CCircuitPolygon *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_RECT)
				bRet = ExportCircuitUnitRect(pBlockDef, (CCircuitRectangle *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE)
				bRet = ExportCircuitUnitEllipse(pBlockDef, (CCircuitEllipse *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE_ARC)
				bRet = ExportCircuitUnitEllipseArc(pBlockDef, (CCircuitEllipseArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POWERPORT)
				bRet = ExportCircuitUnitPowerPort(pBlockDef, (CCircuitPowerPort *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BUSENTRY)
				bRet = ExportCircuitUnitBusEntry(pBlockDef, (CCircuitBusEntry *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_JUNCTION)
				bRet = ExportCircuitUnitJunction(pBlockDef, (CCircuitJunction *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ROUNDRECT)
				bRet = ExportCircuitUnitRoundRect(pBlockDef, (CCircuitRoundRect *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEXTFRAME)
				bRet = ExportCircuitUnitTextFrame(pBlockDef, (CCircuitTextFrame *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NETLABEL)
				bRet = ExportCircuitUnitNetLabel(pBlockDef, (CCircuitNetLabel *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NOERC)
				bRet = ExportCircuitUnitNoERC(pBlockDef, (CCircuitNoERC *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PROBE)
				bRet = ExportCircuitUnitSimProbe(pBlockDef, (CCircuitSimProbe *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_STIMULUS)
				bRet = ExportCircuitUnitSimStimulus(pBlockDef, (CCircuitSimStimulus *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEST_VECTOR)
				bRet = ExportCircuitUnitSimVector(pBlockDef, (CCircuitSimVector *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BEZIRE)
				bRet = ExportCircuitUnitBezier(pBlockDef, (CCircuitBezier *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_GRAPHIC)
				bRet = ExportCircuitUnitGraphic(pBlockDef, (CCircuitGraph *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIECHART)
				bRet = ExportCircuitUnitPieChart(pBlockDef, (CCircuitPieChart *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PCBLAYOUT)
				bRet = ExportCircuitUnitPCBLayoout(pBlockDef,(CCircuitLayoutDirective*)pSonUnit,lLayerId);
			//else if(ct==CIRCUIT_SHEETSYMBOL)
			//	ExportCircuitUnit(pBlockDef, (CCircuitSheetSymbol *)pSonUnit, lLayerId, mat);
			//else if(ct==CIRCUIT_SHEETENTRY)
			//	ExportCircuitUnit(pBlockDef, (CCircuitSheetEntry *)pSonUnit, lLayerId, mat);
			//else if(ct==CIRCUIT_PROCCONTAINER)
			//	ExportCircuitUnit(pBlockDef, (CCircuit *)pSonUnit, lLayerId, mat);
			if (!bRet)
			{
				return false;
			}
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportDsnCircuitPart(IAcadBlock *pBlockDef, DsnCircuitPart *pPart, long lLayerId)
{
	if (IsStopLayerExport())
		return false;
	DsnCircuitPartDisObj* disObj = (DsnCircuitPartDisObj*)pPart->GetDisplayObjByLayerID(lLayerId);
	if (!disObj)
	{
		return true;
	}
	//绘制组件名称
// 	CPartDesignator *pNameInfo = pPart->GetDesignator();
// 	if (pNameInfo && !pNameInfo->IsHide())
// 	{
// 		bool bRet =		ExportPartDesignator(pBlockDef, pNameInfo, true,  pair<double, double>( pPart->GetBoxMaxX(), pPart->GetBoxMaxY()-10 ));
// 		if (!bRet)
// 			return false;
// 	}

	//绘制组件值
// 	CPartDesignator *pValueInfo = pPart->GetTypeValue();
// 	if (pValueInfo && !pValueInfo->IsHide())
// 	{
// 		bool bRet =		ExportPartDesignator(pBlockDef, pValueInfo, true,  pair<double, double>( pPart->GetBoxMaxX(), pPart->GetBoxMaxY()-30 ));
// 		if (!bRet)
// 			return false;
// 	}

	vector<CTinyCADParam*> vecParams = pPart->GetParameterList();
	for ( int i = 0; i < vecParams.size(); ++i )
	{
		CTinyCADParam* pParam = vecParams[ i ];
		if ( pParam && !pParam->IsHidden() )
		{
			bool bRet = ExportTinyCADCircuitPartParam(pBlockDef, vecParams[ i ] );
			if (!bRet)
				return false;
		}
	}

	bool bIsMirrowed=pPart->IsMirrowed();
	int rotateNum = pPart->GetDsnRotateNum(); 
	double dblRotateAngle=disObj->getPartRotateAngle(rotateNum, bIsMirrowed);
	if (bIsMirrowed)
	{
		dblRotateAngle = dblRotateAngle > 180 ? dblRotateAngle-180:dblRotateAngle+180;
	}
	double dblTransX=pPart->GetPosX();
	double dblTransY=pPart->GetPosY();
	double centerX = (pPart->GetBoxMaxX() + pPart->GetBoxMinX())/2.0;
	double centerY = (pPart->GetBoxMaxY() + pPart->GetBoxMinY())/2.0;
	double move_x = 0.0;
	double move_y =0.0;
	double box_length = pPart->GetBoxMaxX() - pPart->GetBoxMinX();
	double box_height = pPart->GetBoxMaxY() - pPart->GetBoxMinY();
	if(abs(dblRotateAngle - 90.0) < 0.01|| abs(dblRotateAngle - 270.0) < 0.01)
	{
		move_x = ( box_length - box_height )/2;
		move_y = move_x;
	}

	CTransform translate=CTransform::translate(-centerX , -centerY , 0);
	CTransform rotate=CTransform::rotate(dblRotateAngle*PI/180.0, 0, 0, 1);
	CTransform translate1=CTransform::translate((rotateNum & 3) < 2 ? centerX : (centerX + move_x) ,(rotateNum & 3) < 2?  centerY : (centerY+move_y) , 0);
	CTransform ts= rotate*translate*translate1;
	// 	if(bIsMirrowed)
	// 	{
	// 		CTransform mirror=CTransform::MirrorByPlane(CVec(0.0, 1.0, 0));
	// 		ts=mirror*ts;
	// 	}

	//dsj 20190718 修改元件位置错误的问题
	CPos center_pos(centerX , centerY , 0);
	CPos mirrowed_center(center_pos);
	if(bIsMirrowed)
	{
		CTransform mirror=CTransform::MirrorByPlane(CVec(1.0, 0.0, 0));
		ts=mirror*ts;

		mirrowed_center = CPos(-centerX , centerY , 0);
		CVec vec = center_pos - mirrowed_center;
		CTransform tr2 = CTransform::translate(vec.GetVecX(), vec.GetVecY(),0);
		ts *= tr2;
	}
	else if (rotateNum == 1)	//rotateNum == 1时，bIsMirrowed=false，但仍有镜像
	{
		CTransform mirror=CTransform::MirrorByPlane(CVec(0, 1.0, 0));
		ts=mirror*ts;

		mirrowed_center = CPos(centerX , -centerY , 0);
		CVec vec = center_pos - mirrowed_center;
		CTransform tr2 = CTransform::translate(vec.GetVecX(), vec.GetVecY(),0);
		ts *= tr2;
	}

	if (fabs(dblRotateAngle) > 1e-6)
	{
		CPos rotated_center = rotate.TransformPos(mirrowed_center);
		CVec vec = mirrowed_center - rotated_center;
		CTransform translate2 = CTransform::translate(vec.GetVecX(), vec.GetVecY(),0);
		ts *= translate2;
	}

	double mat[16];
	ts.GetDataInColFirst(mat);

	std::list<CCircuitUnit *> lstSonUnits;
	// 	ePartShowType type = pPart->GetShowType();
	// 	switch (type)
	// 	{
	// 	case NORMAL_SHOW_TYPE:
	lstSonUnits = pPart->GetNormalUnitList();
	//		break;
	// 
	// 	case DEMORGAN_SHOW_TYPE:
	// 		lstSonUnits = pPart->GetDeMorganUnitList();
	// 		break;
	// 
	// 	case IEEE_SHOW_TYPE:
	// 		lstSonUnits = pPart->GetIEEEUnitList();
	// 		break;
	// 	}
	bool bRet = true;
	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSonUnits.begin(); it_son!=lstSonUnits.end(); it_son++)
	{
		CCircuitUnit *pSonUnit = *it_son;
		CDisplayObj *pSonUnitDis = pSonUnit->GetDisplayObjByLayerID(lLayerId);
		if (pSonUnitDis)
		{
			eCircuitUnitEntType  ct=pSonUnit->GetUnitType();

			if(ct==CIRCUIT_ANNOTATION)
				bRet = ExportCircuitUnitAnnotation(pBlockDef, (CCircuitAnnotation *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIN)
				bRet = ExportCircuitUnitPin(pBlockDef, (CCircuitPin *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ARC)
				bRet = ExportCircuitUnitArc(pBlockDef, (CCircuitArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_LINE)
				bRet = ExportCircuitUnitLine(pBlockDef, (CCircuitLine *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYLINE)
				bRet = ExportCircuitUnitPolyline(pBlockDef, (CCircuitPolyline *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYGON)
				bRet = ExportCircuitUnitPolygon(pBlockDef, (CCircuitPolygon *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_RECT)
				bRet = ExportCircuitUnitRect(pBlockDef, (CCircuitRectangle *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE)
				bRet = ExportCircuitUnitEllipse(pBlockDef, (CCircuitEllipse *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE_ARC)
				bRet = ExportCircuitUnitEllipseArc(pBlockDef, (CCircuitEllipseArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POWERPORT)
				bRet = ExportCircuitUnitPowerPort(pBlockDef, (CCircuitPowerPort *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BUSENTRY)
				bRet = ExportCircuitUnitBusEntry(pBlockDef, (CCircuitBusEntry *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_JUNCTION)
				bRet = ExportCircuitUnitJunction(pBlockDef, (CCircuitJunction *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ROUNDRECT)
				bRet = ExportCircuitUnitRoundRect(pBlockDef, (CCircuitRoundRect *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEXTFRAME)
				bRet = ExportCircuitUnitTextFrame(pBlockDef, (CCircuitTextFrame *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NETLABEL)
				bRet = ExportCircuitUnitNetLabel(pBlockDef, (CCircuitNetLabel *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NOERC)
				bRet = ExportCircuitUnitNoERC(pBlockDef, (CCircuitNoERC *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PROBE)
				bRet = ExportCircuitUnitSimProbe(pBlockDef, (CCircuitSimProbe *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_STIMULUS)
				bRet = ExportCircuitUnitSimStimulus(pBlockDef, (CCircuitSimStimulus *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEST_VECTOR)
				bRet = ExportCircuitUnitSimVector(pBlockDef, (CCircuitSimVector *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BEZIRE)
				bRet = ExportCircuitUnitBezier(pBlockDef, (CCircuitBezier *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_GRAPHIC)
				bRet = ExportCircuitUnitGraphic(pBlockDef, (CCircuitGraph *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIECHART)
				bRet = ExportCircuitUnitPieChart(pBlockDef, (CCircuitPieChart *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PCBLAYOUT)
				bRet = ExportCircuitUnitPCBLayoout(pBlockDef,(CCircuitLayoutDirective*)pSonUnit,lLayerId);
			//else if(ct==CIRCUIT_SHEETSYMBOL)
			//	ExportCircuitUnit(pBlockDef, (CCircuitSheetSymbol *)pSonUnit, lLayerId, mat);
			//else if(ct==CIRCUIT_SHEETENTRY)
			//	ExportCircuitUnit(pBlockDef, (CCircuitSheetEntry *)pSonUnit, lLayerId, mat);
			//else if(ct==CIRCUIT_PROCCONTAINER)
			//	ExportCircuitUnit(pBlockDef, (CCircuit *)pSonUnit, lLayerId, mat);
			if (!bRet)
			{
				return false;
			}
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportAltiumCircuitPart(IAcadBlock *pBlockDef, CAltiumCircuitPart *pPart, long lLayerId)
{
	if (IsStopLayerExport())
		return false;
	CAltiumCircuitPartDisObj* disObj = (CAltiumCircuitPartDisObj*)pPart->GetDisplayObjByLayerID(lLayerId);
	if (!disObj)
	{
		return true;
	}

	//绘制组件名称
	CPartDesignator *pNameInfo = pPart->GetDesignator();
	if (pNameInfo && !pNameInfo->IsHide())
	{
		bool bRet =		ExportPartDesignator(pBlockDef, pNameInfo);
		if (!bRet)
			return false;
	}

	//绘制组件值
	CPartDesignator *pValueInfo = pPart->GetTypeValue();
	if (pValueInfo && !pValueInfo->IsHide())
	{
		bool bRet =		ExportPartDesignator(pBlockDef, pValueInfo);
		if (!bRet)
			return false;
	}

	for (int i = 0; i < pPart->GetParameterList().size(); ++i)
	{
		CAltiumCircuitParam* pParam = pPart->GetParameterList()[i];
		if (pParam && !pParam->IsHidden() && pParam->GetName().Compare(_T("Comment")) != 0)
		{
			bool bRet = ExportAltiumCircuitPartParam(pBlockDef, pPart->GetParameterList()[i]);
			if (!bRet)
				return false;
		}
	}

	//Alium中子单元存储的都是最终的坐标位置，无需作旋转、镜像和平移操作。
	double mat[16] = {1,0,0,0,
	0,1,0,0,
	0,0,1,0,
	0,0,0,1};

	std::list<CCircuitUnit *> lstSonUnits;
	lstSonUnits = pPart->GetNormalUnitList();

	bool bRet = true;
	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSonUnits.begin(); it_son!=lstSonUnits.end(); it_son++)
	{
		CCircuitUnit *pSonUnit = *it_son;
		CDisplayObj *pSonUnitDis = pSonUnit->GetDisplayObjByLayerID(lLayerId);
		if (pSonUnitDis)
		{
			eCircuitUnitEntType  ct=pSonUnit->GetUnitType();

			if(ct==CIRCUIT_ANNOTATION)
				bRet = ExportCircuitUnitAnnotation(pBlockDef, (CCircuitAnnotation *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIN || ct == ALTIUM_CIRCUIT_PIN)
				bRet = ExportCircuitUnitPin(pBlockDef, (CCircuitPin *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ARC)
				bRet = ExportCircuitUnitArc(pBlockDef, (CCircuitArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_LINE)
				bRet = ExportCircuitUnitLine(pBlockDef, (CCircuitLine *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYLINE)
				bRet = ExportCircuitUnitPolyline(pBlockDef, (CCircuitPolyline *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYGON)
				bRet = ExportCircuitUnitPolygon(pBlockDef, (CCircuitPolygon *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_RECT)
				bRet = ExportCircuitUnitRect(pBlockDef, (CCircuitRectangle *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE)
				bRet = ExportCircuitUnitEllipse(pBlockDef, (CCircuitEllipse *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE_ARC)
				bRet = ExportCircuitUnitEllipseArc(pBlockDef, (CCircuitEllipseArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POWERPORT)
				bRet = ExportCircuitUnitPowerPort(pBlockDef, (CCircuitPowerPort *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BUSENTRY)
				bRet = ExportCircuitUnitBusEntry(pBlockDef, (CCircuitBusEntry *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_JUNCTION)
				bRet = ExportCircuitUnitJunction(pBlockDef, (CCircuitJunction *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ROUNDRECT)
				bRet = ExportCircuitUnitRoundRect(pBlockDef, (CCircuitRoundRect *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEXTFRAME)
				bRet = ExportCircuitUnitTextFrame(pBlockDef, (CCircuitTextFrame *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NETLABEL)
				bRet = ExportCircuitUnitNetLabel(pBlockDef, (CCircuitNetLabel *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NOERC)
				bRet = ExportCircuitUnitNoERC(pBlockDef, (CCircuitNoERC *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PROBE)
				bRet = ExportCircuitUnitSimProbe(pBlockDef, (CCircuitSimProbe *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_STIMULUS)
				bRet = ExportCircuitUnitSimStimulus(pBlockDef, (CCircuitSimStimulus *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEST_VECTOR)
				bRet = ExportCircuitUnitSimVector(pBlockDef, (CCircuitSimVector *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BEZIRE)
				bRet = ExportCircuitUnitBezier(pBlockDef, (CCircuitBezier *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_GRAPHIC)
				bRet = ExportCircuitUnitGraphic(pBlockDef, (CCircuitGraph *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIECHART)
				bRet = ExportCircuitUnitPieChart(pBlockDef, (CCircuitPieChart *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PCBLAYOUT)
				bRet = ExportCircuitUnitPCBLayoout(pBlockDef,(CCircuitLayoutDirective*)pSonUnit,lLayerId);
			if (!bRet)
			{
				return false;
			}
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportMentorCircuitPart(IAcadBlock *pBlockDef, MentorCircuitPart *pPart, long lLayerId)
{
	if (IsStopLayerExport())
		return false;
	MentorCircuitPartDisObj* disObj = (MentorCircuitPartDisObj*)pPart->GetDisplayObjByLayerID(lLayerId);
	if (!disObj)
	{
		return true;
	}

	bool bIsMirrored = pPart->IsMirrowed();
	int iMirrorType = pPart->GetMirrorType(); //0:no; 1:x; 2:y; 3:x&y
	double dblRotateAngle=pPart->GetRotateAngle();
	double dblTransX=pPart->GetPosX();
	double dblTransY=pPart->GetPosY();
	CTransform translate=CTransform::translate(dblTransX , dblTransY , 0);
	CTransform rotate=CTransform::rotate(dblRotateAngle*PI/180.0, 0, 0, 1);
	CTransform ts = translate;
	switch (iMirrorType)
	{
	case 1:
		{
			CTransform mirror=CTransform::MirrorByPlane(CVec(1.0, 0.0, 0.0));
			ts=mirror*ts;
			break;
		}
	case 2:
		{
			CTransform mirror=CTransform::MirrorByPlane(CVec(0.0, 1.0, 0.0));
			ts=mirror*ts;
			break;
		}
	case 3:
		{
			CTransform mirror1=CTransform::MirrorByPlane(CVec(1.0, 0.0, 0.0));
			ts=mirror1*ts;
			CTransform mirror2=CTransform::MirrorByPlane(CVec(0.0, 1.0, 0.0));
			ts=mirror2*ts;
			break;
		}
	}
	ts = rotate*ts;
	double mat[16];
	ts.GetDataInColFirst(mat);

	//绘制组件名称
	CPartDesignator *pNameInfo = pPart->GetDesignator();
	if (pNameInfo && !pNameInfo->IsHide())
	{
		bool bRet =		ExportMentorPartDesignator(pBlockDef, pNameInfo, ts);
		if (!bRet)
			return false;
	}

	//绘制组件值
	CPartDesignator *pValueInfo = pPart->GetTypeValue();
	if (pValueInfo && !pValueInfo->IsHide())
	{
		bool bRet =		ExportMentorPartDesignator(pBlockDef, pValueInfo, ts);
		if (!bRet)
			return false;
	}

	//绘制组件类型
	CPartDesignator *pPartType = pPart->GetPartTypeDesignator();
	if (pPartType && !pPartType->IsHide())
	{
		bool bRet =		ExportMentorPartDesignator(pBlockDef, pPartType, ts);
		if (!bRet)
			return false;
	}

	std::list<CCircuitUnit *> lstSonUnits;
	lstSonUnits = pPart->GetNormalUnitList();

	bool bRet = true;
	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSonUnits.begin(); it_son!=lstSonUnits.end(); it_son++)
	{
		CCircuitUnit *pSonUnit = *it_son;
		CDisplayObj *pSonUnitDis = pSonUnit->GetDisplayObjByLayerID(lLayerId);
		if (pSonUnitDis)
		{
			eCircuitUnitEntType  ct=pSonUnit->GetUnitType();

			if(ct==CIRCUIT_ANNOTATION)
				bRet = ExportCircuitUnitAnnotation(pBlockDef, (CCircuitAnnotation *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIN)
				bRet = ExportCircuitUnitPin(pBlockDef, (CCircuitPin *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ARC)
				bRet = ExportCircuitUnitArc(pBlockDef, (CCircuitArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_LINE)
				bRet = ExportCircuitUnitLine(pBlockDef, (CCircuitLine *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYLINE)
				bRet = ExportCircuitUnitPolyline(pBlockDef, (CCircuitPolyline *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYGON)
				bRet = ExportCircuitUnitPolygon(pBlockDef, (CCircuitPolygon *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_RECT)
				bRet = ExportCircuitUnitRect(pBlockDef, (CCircuitRectangle *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE)
				bRet = ExportCircuitUnitEllipse(pBlockDef, (CCircuitEllipse *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE_ARC)
				bRet = ExportCircuitUnitEllipseArc(pBlockDef, (CCircuitEllipseArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POWERPORT)
				bRet = ExportCircuitUnitPowerPort(pBlockDef, (CCircuitPowerPort *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BUSENTRY)
				bRet = ExportCircuitUnitBusEntry(pBlockDef, (CCircuitBusEntry *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_JUNCTION)
				bRet = ExportCircuitUnitJunction(pBlockDef, (CCircuitJunction *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ROUNDRECT)
				bRet = ExportCircuitUnitRoundRect(pBlockDef, (CCircuitRoundRect *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEXTFRAME)
				bRet = ExportCircuitUnitTextFrame(pBlockDef, (CCircuitTextFrame *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NETLABEL)
				bRet = ExportCircuitUnitNetLabel(pBlockDef, (CCircuitNetLabel *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NOERC)
				bRet = ExportCircuitUnitNoERC(pBlockDef, (CCircuitNoERC *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PROBE)
				bRet = ExportCircuitUnitSimProbe(pBlockDef, (CCircuitSimProbe *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_STIMULUS)
				bRet = ExportCircuitUnitSimStimulus(pBlockDef, (CCircuitSimStimulus *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEST_VECTOR)
				bRet = ExportCircuitUnitSimVector(pBlockDef, (CCircuitSimVector *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BEZIRE)
				bRet = ExportCircuitUnitBezier(pBlockDef, (CCircuitBezier *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_GRAPHIC)
				bRet = ExportCircuitUnitGraphic(pBlockDef, (CCircuitGraph *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIECHART)
				bRet = ExportCircuitUnitPieChart(pBlockDef, (CCircuitPieChart *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PCBLAYOUT)
				bRet = ExportCircuitUnitPCBLayoout(pBlockDef,(CCircuitLayoutDirective*)pSonUnit,lLayerId);
			else if (ct == MENTOR_CIRCUIT_PART)
				bRet = ExportMentorCircuitSubPart(pBlockDef, (MentorCircuitPart*)pSonUnit, lLayerId, ts);

			if (!bRet)
			{
				return false;
			}
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportMentorCircuitSubPart(IAcadBlock *pBlockDef, MentorCircuitPart *pPart, long lLayerId, CTransform ts)
{
	if (IsStopLayerExport())
		return false;
	MentorCircuitPartDisObj* disObj = (MentorCircuitPartDisObj*)pPart->GetDisplayObjByLayerID(lLayerId);
	if (!disObj)
	{
		return true;
	}

	bool bIsMirrored = pPart->IsMirrowed();
	int iMirrorType = pPart->GetMirrorType(); //0:no; 1:x; 2:y; 3:x&y
	double dblRotateAngle=pPart->GetRotateAngle();
	double dblTransX=pPart->GetPosX();
	double dblTransY=pPart->GetPosY();
	CTransform translate=CTransform::translate(dblTransX , dblTransY , 0);
	CTransform rotate=CTransform::rotate(dblRotateAngle*PI/180.0, 0, 0, 1);
	ts = (/*rotate**/translate)*ts;
	switch (iMirrorType)
	{
	case 1:
		{
			CTransform mirror=CTransform::MirrorByPlane(CVec(1.0, 0.0, 0.0));
			ts=mirror*ts;
			break;
		}
	case 2:
		{
			CTransform mirror=CTransform::MirrorByPlane(CVec(0.0, 1.0, 0.0));
			ts=mirror*ts;
			break;
		}
	case 3:
		{
			CTransform mirror1=CTransform::MirrorByPlane(CVec(1.0, 0.0, 0.0));
			ts=mirror1*ts;
			CTransform mirror2=CTransform::MirrorByPlane(CVec(0.0, 1.0, 0.0));
			ts=mirror2*ts;
			break;
		}
	}
	ts = rotate*ts;
	double mat[16];
	ts.GetDataInColFirst(mat);

	//绘制组件名称
	CPartDesignator *pNameInfo = pPart->GetDesignator();
	if (pNameInfo && !pNameInfo->IsHide())
	{
		bool bRet =		ExportMentorPartDesignator(pBlockDef, pNameInfo, ts);
		if (!bRet)
			return false;
	}

	//绘制组件值
	CPartDesignator *pValueInfo = pPart->GetTypeValue();
	if (pValueInfo && !pValueInfo->IsHide())
	{
		bool bRet =		ExportMentorPartDesignator(pBlockDef, pValueInfo, ts);
		if (!bRet)
			return false;
	}

	//绘制组件类型
	CPartDesignator *pPartType = pPart->GetPartTypeDesignator();
	if (pPartType && !pPartType->IsHide())
	{
		bool bRet =		ExportMentorPartDesignator(pBlockDef, pPartType, ts);
		if (!bRet)
			return false;
	}

	std::list<CCircuitUnit *> lstSonUnits;
	lstSonUnits = pPart->GetNormalUnitList();

	bool bRet = true;
	list<CCircuitUnit *>::iterator it_son;
	for (it_son=lstSonUnits.begin(); it_son!=lstSonUnits.end(); it_son++)
	{
		CCircuitUnit *pSonUnit = *it_son;
		CDisplayObj *pSonUnitDis = pSonUnit->GetDisplayObjByLayerID(lLayerId);
		if (pSonUnitDis)
		{
			eCircuitUnitEntType  ct=pSonUnit->GetUnitType();

			if(ct==CIRCUIT_ANNOTATION)
				bRet = ExportCircuitUnitAnnotation(pBlockDef, (CCircuitAnnotation *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIN)
				bRet = ExportCircuitUnitPin(pBlockDef, (CCircuitPin *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ARC)
				bRet = ExportCircuitUnitArc(pBlockDef, (CCircuitArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_LINE)
				bRet = ExportCircuitUnitLine(pBlockDef, (CCircuitLine *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYLINE)
				bRet = ExportCircuitUnitPolyline(pBlockDef, (CCircuitPolyline *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POLYGON)
				bRet = ExportCircuitUnitPolygon(pBlockDef, (CCircuitPolygon *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_RECT)
				bRet = ExportCircuitUnitRect(pBlockDef, (CCircuitRectangle *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE)
				bRet = ExportCircuitUnitEllipse(pBlockDef, (CCircuitEllipse *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ELLIPSE_ARC)
				bRet = ExportCircuitUnitEllipseArc(pBlockDef, (CCircuitEllipseArc *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_POWERPORT)
				bRet = ExportCircuitUnitPowerPort(pBlockDef, (CCircuitPowerPort *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BUSENTRY)
				bRet = ExportCircuitUnitBusEntry(pBlockDef, (CCircuitBusEntry *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_JUNCTION)
				bRet = ExportCircuitUnitJunction(pBlockDef, (CCircuitJunction *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_ROUNDRECT)
				bRet = ExportCircuitUnitRoundRect(pBlockDef, (CCircuitRoundRect *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEXTFRAME)
				bRet = ExportCircuitUnitTextFrame(pBlockDef, (CCircuitTextFrame *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NETLABEL)
				bRet = ExportCircuitUnitNetLabel(pBlockDef, (CCircuitNetLabel *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_NOERC)
				bRet = ExportCircuitUnitNoERC(pBlockDef, (CCircuitNoERC *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PROBE)
				bRet = ExportCircuitUnitSimProbe(pBlockDef, (CCircuitSimProbe *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_STIMULUS)
				bRet = ExportCircuitUnitSimStimulus(pBlockDef, (CCircuitSimStimulus *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_TEST_VECTOR)
				bRet = ExportCircuitUnitSimVector(pBlockDef, (CCircuitSimVector *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_BEZIRE)
				bRet = ExportCircuitUnitBezier(pBlockDef, (CCircuitBezier *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_GRAPHIC)
				bRet = ExportCircuitUnitGraphic(pBlockDef, (CCircuitGraph *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PIECHART)
				bRet = ExportCircuitUnitPieChart(pBlockDef, (CCircuitPieChart *)pSonUnit, lLayerId, mat);
			else if(ct==CIRCUIT_PCBLAYOUT)
				bRet = ExportCircuitUnitPCBLayoout(pBlockDef,(CCircuitLayoutDirective*)pSonUnit,lLayerId);
			else if (ct == MENTOR_CIRCUIT_PART)
				bRet = ExportMentorCircuitSubPart(pBlockDef, (MentorCircuitPart*)pSonUnit, lLayerId, ts);

			if (!bRet)
			{
				return false;
			}
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitWire(IAcadBlock *pBlockDef, CCircuitWire *pWire, long lLayerId)
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pWire->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	std::list<double> PosList=pWire->GetPosList();
	long lPtSize=PosList.size();
	long pts_size=(long(lPtSize/2))*3;
	double * pts=new double[pts_size];

	std::list<double>::const_iterator iter;
	int i=0;
	for(iter=PosList.begin(); iter!=PosList.end() && i<pts_size; ++iter)
	{
		pts[i]=*iter;
		i++;

		if((i+1)%3==0)
		{
			pts[i]=0;
			i++;
		}
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_FALSE);

	if(pWire->GetLineWidth()>1.0001)
		pPolyline->put_ConstantWidth(pWire->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pWire->GetColorR()*255), (long)(pWire->GetColorG()*255), (long)(pWire->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	pPolyline->Release();

	delete []pts;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitBus(IAcadBlock *pBlockDef, CCircuitBus *pBus, long lLayerId)
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pBus->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	std::list<double> PosList=pBus->GetPosList();
	long lPtSize=PosList.size();
	long pts_size=(long(lPtSize/2))*3;
	double * pts=new double[pts_size];

	std::list<double>::const_iterator iter;
	int i=0;
	for(iter=PosList.begin(); iter!=PosList.end() && i<pts_size; ++iter)
	{
		pts[i]=*iter;
		i++;

		if((i+1)%3==0)
		{
			pts[i]=0;
			i++;
		}
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	if(pPolyline)
		return false;
	if(pBus->GetLineWidth()>1.0001)
		pPolyline->put_ConstantWidth(pBus->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pBus->GetColorR()*255), (long)(pBus->GetColorG()*255), (long)(pBus->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	//if(mat)
	//{
	//	VARIANT vtMat;
	//	CreateMatVariant(mat, vtMat);
	//	pPolyline->TransformBy(vtMat);
	//	::VariantClear(&vtMat);
	//	//pPolyline->Update();
	//}

	pPolyline->Release();

	delete []pts;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPin(IAcadBlock *pBlockDef, CCircuitPin *pPin, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pPin->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblRotateAngle=pPin->GetRotaAngle();
	double rotate_angle=dblRotateAngle*PI/180.0;
	double dblPosX=pPin->GetPosX();
	double dblPosY=pPin->GetPosY();

	CTransform translate=CTransform::translate(dblPosX, dblPosY, 0);
	CTransform rotate=CTransform::rotate(rotate_angle, 0, 0, 1);
	CTransform ts=rotate*translate;

	double ts_form[16];
	ts.GetDataInColFirst(ts_form);
	VARIANT vtTsForm;
	CreateMatVariant(ts_form, vtTsForm);

	double dblLen = pPin->GetPinLength();
	bool bShowName = pPin->IsShowPinName();
	bool bShowIndex = pPin->IsShowPinIndex();
	bool bDotSymbol = pPin->IsExistDotSymbol();
	bool bClkSymbol = pPin->IsExistClkSymbol();

	//画引脚线
	if (!bDotSymbol)
	{
		long pts_size=6;
		double pts[]={0, 0, 0, dblLen, 0, 0};

		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvPts =  (LPVARIANT)saPts;     

		IAcadPolyline *pPolyline=NULL;
		pBlockDef->AddPolyline(*pvPts, &pPolyline);
		pPolyline->put_Closed(VARIANT_FALSE);
		if (!pPolyline)
			return false;

		//if(pCircuitLine->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(0.4);//HOOPS与ACAD中宽度的显示效果不同
		pPolyline->TransformBy(vtTsForm);

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(0), (long)(0), (long)(0));
			pPolyline->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pPolyline->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}

		pPolyline->Release();
	}

	//画引脚名称
	if (bShowName)
	{
		CString szContent=pPin->GetPinName();
		CCircuitPart *pPart = (CCircuitPart *)pPin->GetParentEntity();
		CString strFontName=_T("Times New Roman");
		double dblTextSize=6.0;
		CCircuitFont *pFont = new CCircuitFont();//pPart->GetFont();
		if(pFont)
		{
			strFontName=pFont->GetFontName();
			dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
		}
		delete pFont;

		//设置文字方向和旋转角度
		double dblRotateAngleInDegree = pPin->GetRotaAngle();
		double dblRotateAngle=dblRotateAngleInDegree*PI/180.0;

		long pts_size=3;
		double pts[]={-6, 0, 0};

		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saPts;     

		IAcadText *pText=NULL;
		pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(0), (long)(0), (long)(0));
			pText->put_TrueColor(pColor);
			pColor->Release();
		}

		if(fabs(dblRotateAngleInDegree-180)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentLeft);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		else if(fabs(dblRotateAngleInDegree)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentRight);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		else if(fabs(dblRotateAngleInDegree-90)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentRight);
			pText->put_Rotation(PI*0.5);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		else if(fabs(dblRotateAngleInDegree-270)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentLeft);
			pText->put_Rotation(PI*0.5);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		pText->TransformBy(vtTsForm);

		if(fabs(dblRotateAngleInDegree-180)<1 || fabs(dblRotateAngleInDegree)<1)
			pText->put_Rotation(0);
		else if(fabs(dblRotateAngleInDegree-90)<1 || fabs(dblRotateAngleInDegree-270)<1)
			pText->put_Rotation(PI*0.5);

		CString strTextStyle=GetOrCreateTextStyle(pBlockDef, strFontName);
		if(!strTextStyle.IsEmpty())
			pText->put_StyleName(_bstr_t(strTextStyle));

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pText->TransformBy(vtMat);
			::VariantClear(&vtMat);
		}

		pText->Release();
	}

	//画引脚序号
	if (bShowIndex)
	{
		CString szContent=pPin->GetPinIndex();
		CCircuitPart *pPart = (CCircuitPart *)pPin->GetParentEntity();
		CString strFontName=_T("Times New Roman");
		double dblTextSize=6.0;
		CCircuitFont *pFont = new CCircuitFont();//pPart->GetFont();
		if(pFont)
		{
			strFontName=pFont->GetFontName();
			dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
		}
		delete pFont;

		//设置文字方向和旋转角度
		double dblRotateAngleInDegree = pPin->GetRotaAngle();
		double dblRotateAngle=dblRotateAngleInDegree*PI/180.0;

		long pts_size=3;
		double pts[]={dblLen, 0, 0};

		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saPts;

		////only for test
		//if(fabs(dblRotateAngleInDegree-180)<1)
		//{
		//	szContent+=_T("_180");
		//}
		//else if(fabs(dblRotateAngleInDegree)<1)
		//{
		//	szContent+=_T("_0");
		//}
		//else if(fabs(dblRotateAngleInDegree-90)<1)
		//{
		//	szContent+=_T("_90");
		//}
		//else if(fabs(dblRotateAngleInDegree-270)<1)
		//{
		//	szContent+=_T("_270");
		//}

		IAcadText *pText=NULL;
		pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(0), (long)(0), (long)(0));
			pText->put_TrueColor(pColor);
			pColor->Release();
		}

		if(fabs(dblRotateAngleInDegree-180)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentLeft);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		else if(fabs(dblRotateAngleInDegree)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentRight);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		else if(fabs(dblRotateAngleInDegree-90)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentRight);
			pText->put_Rotation(PI*0.5);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		else if(fabs(dblRotateAngleInDegree-270)<1)
		{
			pText->put_Alignment(AutoCAD::acAlignmentLeft);
			pText->put_Rotation(PI*0.5);

			pText->put_TextAlignmentPoint(*pvInsertPts);
		}
		pText->TransformBy(vtTsForm);

		if(fabs(dblRotateAngleInDegree-180)<1 || fabs(dblRotateAngleInDegree)<1)
			pText->put_Rotation(0);
		else if(fabs(dblRotateAngleInDegree-90)<1 || fabs(dblRotateAngleInDegree-270)<1)
			pText->put_Rotation(PI*0.5);

		CString strTextStyle=GetOrCreateTextStyle(pBlockDef, strFontName);
		if(!strTextStyle.IsEmpty())
			pText->put_StyleName(_bstr_t(strTextStyle));

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pText->TransformBy(vtMat);
			::VariantClear(&vtMat);
		}

		pText->Release();
	}

	//画小圆标记
	if (bDotSymbol)
	{
		//HPoint center, major, minor;
		//center.x=3; center.y=0; center.z=0;
		//major.x=6; major.y=0; major.z=0;
		//minor.x=3; minor.y=3; minor.z=0;
		//HC_Insert_Elliptical_Arc(&center, &major, &minor, 0, 1);
		long pts_size=3;
		double pts[]={3, 0, 0};

		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvPts =  (LPVARIANT)saPts;     

		pts[0]=3;
		pts[1]=0;

		COleSafeArray major;
		major.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvMajor =  (LPVARIANT)major;

		double dblRatio=1;

		IAcadEllipse *pEllipse=NULL;
		pBlockDef->AddEllipse(*pvPts, *pvMajor, dblRatio, &pEllipse);
		//if(pEllipse->GetBorderWidth()>1.0001)
		//pEllipse->put_ConstantWidth(0.4);//HOOPS与ACAD中宽度的显示效果不同
		pEllipse->TransformBy(vtTsForm);

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pDisplayObj->GetColorR()*255), (long)(pDisplayObj->GetColorG()*255), (long)(pDisplayObj->GetColorB()*255));
			pEllipse->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pEllipse->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}

		pts_size=6;
		double pts2[]={6, 0, 0, dblLen, 0, 0};

		COleSafeArray   saPts2;
		saPts2.CreateOneDim(VT_R8, pts_size, pts2);        
		VARIANT * pvPts2 =  (LPVARIANT)saPts2;     

		IAcadPolyline *pPolyline=NULL;
		pBlockDef->AddPolyline(*pvPts2, &pPolyline);
		pPolyline->put_Closed(VARIANT_FALSE);
		//if(pCircuitLine->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(0.4);//HOOPS与ACAD中宽度的显示效果不同
		pPolyline->TransformBy(vtTsForm);

		pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(0), (long)(0), (long)(0));
			pPolyline->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pPolyline->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}

		pPolyline->Release();
	}

	//画小勾标记
	if (bClkSymbol)
	{
		long pts_size=6;
		double pts[]={0, 3, 0, -3, 0, 0};

		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvPts =  (LPVARIANT)saPts;     

		IAcadPolyline *pPolyline=NULL;
		pBlockDef->AddPolyline(*pvPts, &pPolyline);
		pPolyline->put_Closed(VARIANT_FALSE);
		//if(pCircuitLine->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(0.4);//HOOPS与ACAD中宽度的显示效果不同
		pPolyline->TransformBy(vtTsForm);

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(0), (long)(0), (long)(0));
			pPolyline->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pPolyline->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}

		pPolyline->Release();

		double pts2[]={-3, 0, 0, 0, -3, 0};

		COleSafeArray   saPts2;
		saPts2.CreateOneDim(VT_R8, pts_size, pts2);        
		VARIANT * pvPts2 =  (LPVARIANT)saPts2;     

		IAcadPolyline *pPolyline2=NULL;
		pBlockDef->AddPolyline(*pvPts2, &pPolyline2);
		pPolyline2->put_Closed(VARIANT_FALSE);
		if (!pPolyline2)
		{
			return false;
		}
		//if(pCircuitLine->GetBorderWidth()>1.0001)
		pPolyline2->put_ConstantWidth(0.4);//HOOPS与ACAD中宽度的显示效果不同
		pPolyline2->TransformBy(vtTsForm);

		pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(0), (long)(0), (long)(0));
			pPolyline2->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pPolyline2->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}

		pPolyline2->Release();
	}

	::VariantClear(&vtTsForm);
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPort(IAcadBlock *pBlockDef, CCircuitPort *pPort, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj = pPort->GetDisplayObjByLayerID(lLayerId);
	if( !pDisplayObj )
		return true;

	double dLength = pPort->GetLength();
	ePortStyle portStyle = pPort->GetPortStyle();
	eAlignMode textAllign = pPort->GetAlignMode();

	long pts_size = 0;
	double pts[18];
	//原点坐标位置
	switch (portStyle)
	{

	case HORIZONTAL_NONE:
		{
			pts_size = 12;

			pts[0] = 0;
			pts[1] = -5;
			pts[2] = 0;
			pts[3] = dLength;
			pts[4] = -5;
			pts[5] = 0;
			pts[6] = dLength;
			pts[7] = 5;
			pts[8] = 0;
			pts[9] = 0;
			pts[10] = 5;
			pts[11] = 0;

			break;
		}
	case HORIZONTAL_LEFT:
		{

			pts_size = 15;

			pts[0] = pts[1] = pts[2] = 0;
			pts[3] = 5;
			pts[4] = -5;
			pts[5] = 0;
			pts[6] = dLength;
			pts[7] = -5;
			pts[8] = 0;
			pts[9] = dLength;
			pts[10] = 5;
			pts[11] = 0;
			pts[12] = 5;
			pts[13] = 5;
			pts[14] = 0;

			break;
		}

	case HORIZONTAL_RIGHT:
		{
			pts_size = 15;

			pts[0] = 0;
			pts[1] = -5;
			pts[2] = 0;
			pts[3] = dLength-5;
			pts[4] = -5;
			pts[5] = 0;
			pts[6] = dLength;
			pts[7] = 0;
			pts[8] = 0;
			pts[9] = dLength-5;
			pts[10] = 5;
			pts[11] = 0;
			pts[12] = 0;
			pts[13] = 5;
			pts[14] = 0;

			break;
		}

	case HORIZONTAL_LEFT_RIGHT:
		{
			pts_size=18;

			pts[0] = pts[1] = pts[2] = 0;
			pts[3] = 5;
			pts[4] = -5;
			pts[5] = 0;
			pts[6] = dLength-5;
			pts[7] = -5;
			pts[8] = 0;
			pts[9] = dLength;
			pts[10] = pts[11] = 0;
			pts[12] = dLength-5;
			pts[13] = 5;
			pts[14] = 0;
			pts[15] = pts[16] = 5;
			pts[17] = 0;

			break;
		}
	case VERTICAL_NONE:
		{
			pts_size=12;

			pts[0] = -5;
			pts[1] = pts[2] = 0;
			pts[3] = 5;
			pts[4] = pts[5] = 0;
			pts[6] = 5;
			pts[7] = dLength;
			pts[8] = 0;
			pts[9] = -5;
			pts[10] = dLength;
			pts[11] = 0;

			break;
		}

	case VERTICAL_TOP:
		{
			pts_size = 15;

			pts[0] = -5;
			pts[1] = 0;
			pts[2] = 0;
			pts[3] = 5;
			pts[4] = 0;
			pts[5] = 0;
			pts[6] = 5;
			pts[7] = dLength-5;
			pts[8] = 0;
			pts[9] = 0;
			pts[10] = dLength;
			pts[11] = 0;
			pts[12] = -5;
			pts[13] = dLength-5;
			pts[14] = 0;

			break;
		}


	case VERTICAL_BOTTOM:
		{
			pts_size = 15;

			pts[0] = -5;
			pts[1] = 5;
			pts[2] = 0;
			pts[3] = 0;
			pts[4] = 0;
			pts[5] = 0;
			pts[6] = 5;
			pts[7] = 5;
			pts[8] = 0;
			pts[9] = 5;
			pts[10] = dLength;
			pts[11] = 0;
			pts[12] = -5;
			pts[13] = dLength;
			pts[14] = 0;

			break;
		}

	case VERTICAL_TOP_BOTTOM:
		{
			pts_size=18;

			pts[0] = -5;
			pts[1] = 5;
			pts[2] = 0;
			pts[3] = pts[4] = pts[5] = 0;
			pts[6] = 5;
			pts[7] = 5;
			pts[8] = 0;
			pts[9] = 5;
			pts[10] = dLength-5;
			pts[11] = 0;
			pts[12] = 0;
			pts[13] = dLength;
			pts[14] = 0;
			pts[15] = -5;
			pts[16] = dLength-5;
			pts[17] = 0;

			break;
		}
	default:
		pts_size=18;

		pts[0] = pts[1] = pts[2] = 0;
		pts[3] = 5;
		pts[4] = -5;
		pts[5] = 0;
		pts[6] = dLength-5;
		pts[7] = -5;
		pts[8] = 0;
		pts[9] = dLength;
		pts[10] = pts[11] = 0;
		pts[12] = dLength-5;
		pts[13] = 5;
		pts[14] = 0;
		pts[15] = pts[16] = 5;
		pts[17] = 0;
		break;

	}

	CCircuitPortDisObj *pCircuitPortDisObj = (CCircuitPortDisObj*)pDisplayObj;
	float fMat[16];
	pCircuitPortDisObj->GetTransform().Get3Dtransf(fMat);
	double dMat[16];  //保存矩阵从列开始提取数据
	int n=0;
	for(int j=0;j<4;j++)
	{
		for(int i=0;i<4;i++)
		{
			dMat[n++] = (double)fMat[4*i+j];
		}
	}

	VARIANT varMat;
	CreateMatVariant(dMat,varMat);

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_TRUE);

	pPolyline->put_ConstantWidth(0.4);//HOOPS与ACAD中宽度的显示效果不同
	pPolyline->TransformBy(varMat);
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pPort->GetBorderColorR()*255), (long)(pPort->GetBorderColorG()*255), (long)(pPort->GetBorderColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}
	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
	}
	pPolyline->Release();

	long lPtsTextSize = 3;
	double ptsText[3]={10, -3, g_textCorordZ};

	if(portStyle < VERTICAL_NONE)  //水平
	{
		switch(textAllign)
		{
		case CENTER_MODE:
			{
				ptsText[0] = 0.5*dLength;
				ptsText[1] = -3;
				ptsText[2] = g_textCorordZ;
				break;
			}

		case LEFT_MODE:
			{
				ptsText[0] = 10;
				ptsText[1] = -3;
				ptsText[2] = g_textCorordZ;
				break;;
			}
		case RIGHT_MODE:
			{
				ptsText[0] = dLength-10;
				ptsText[1] = -3;
				ptsText[2] = g_textCorordZ;
				break;;
			}
		default:
			break;

		}
	}
	else  //垂直(暂未处理，没遇到垂直端口例子)
	{
		switch(textAllign)
		{
		case CENTER_MODE:
			{
				ptsText[0] = -3;
				ptsText[1] = 0.5*dLength;
				ptsText[2] = g_textCorordZ;
				break;
			}
		case LEFT_MODE:
			{
				ptsText[0] = -3;
				ptsText[1] = 10;
				ptsText[2] = g_textCorordZ;
				break;
			}
		case RIGHT_MODE:
			{
				ptsText[0] = -3;
				ptsText[1] = dLength-10;
				ptsText[2] = g_textCorordZ;
				break;
			}
		default:
			break;
		}
	}

	CString strContent = pPort->GetText();
	CString strFontName = pCircuitPortDisObj->GetTextFont();
	double dTextSize=6.0;
	CCircuitFont *pFont = new CCircuitFont();
	if(pFont)
	{
		strFontName=pFont->GetFontName();
		dTextSize = pFont->GetSize()*0.6; 
	}
	delete pFont;

	COleSafeArray   saTextPts;
	saTextPts.CreateOneDim(VT_R8, lPtsTextSize, ptsText);        
	VARIANT * pvTextPts =  (LPVARIANT)saTextPts;     

	IAcadText *pText=NULL;
	pBlockDef->AddText(_bstr_t(strContent), *pvTextPts, dTextSize, &pText);
	pText->TransformBy(varMat);

	CString strTextStyle=GetOrCreateTextStyle(pBlockDef, strFontName);
	if(!strTextStyle.IsEmpty())
		pText->put_StyleName(_bstr_t(strTextStyle));

	pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pPort->GetFontColorR()*255), (long)(pPort->GetFontColorG()*255), (long)(pPort->GetFontColorB()*255));
		pText->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pText->TransformBy(vtMat);
		::VariantClear(&vtMat);
	}
	pText->Release();

	::VariantClear(&varMat);

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitAnnotation(IAcadBlock *pBlockDef, CCircuitAnnotation *pAnnotation, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pAnnotation->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	CCircuitUnitDisObj *pCircuitDispObj=(CCircuitUnitDisObj *)pDisplayObj;

	CString szContent = pAnnotation->GetContent();
	double posX = pAnnotation->GetPosX();
	double posY = pAnnotation->GetPosY();
	CCircuitFont *pFont = pAnnotation->GetFont();

	CString strFontName=pFont->GetFontName();

	//double dScaleRatio = 0.02;
	//pCircuitDispObj->GetScaleRatio(dScaleRatio);
	double dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc

	//设置文字方向和旋转角度
	double dblRotateAngleInDegree = pAnnotation->GetRotateAngle();
	double dblRotateAngle=dblRotateAngleInDegree*PI/180.0;

	long pts_size=3;
	double pts[]={posX, posY, 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvInsertPts =  (LPVARIANT)saPts;     
	IAcadText *pText=NULL;
	pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pAnnotation->GetColorR()*255), (long)(pAnnotation->GetColorG()*255), (long)(pAnnotation->GetColorB()*255));
		pText->put_TrueColor(pColor);
		pColor->Release();
	}

	if(fabs(dblRotateAngleInDegree-180)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentRight);

		pText->put_TextAlignmentPoint(*pvInsertPts);
	}
	else if(fabs(dblRotateAngleInDegree)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentLeft);
	}
	else if(fabs(dblRotateAngleInDegree-90)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentLeft);
		pText->put_Rotation(PI*0.5);
	}
	else if(fabs(dblRotateAngleInDegree-270)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentRight);
		pText->put_Rotation(PI*0.5);

		pText->put_TextAlignmentPoint(*pvInsertPts);
	}

	CString strTextStyle=GetOrCreateTextStyle(pBlockDef, strFontName);
	if(!strTextStyle.IsEmpty())
		pText->put_StyleName(_bstr_t(strTextStyle));

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pText->TransformBy(vtMat);
		::VariantClear(&vtMat);
	}

	pText->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitArc(IAcadBlock *pBlockDef, CCircuitArc *pCircuitArc, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pCircuitArc->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	long pts_size=3;
	double pts[]={pCircuitArc->GetPosX(), pCircuitArc->GetPosY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadArc *pArc=NULL;
	pBlockDef->AddArc(*pvPts, pCircuitArc->GetRadius(), pCircuitArc->GetStartAngle()*PI/180.0, pCircuitArc->GetEndAngle()*PI/180.0, &pArc);
	//if(pCircuitArc->GetBorderWidth()>1.0001)
	//	pArc->put_Lineweight(pCircuitArc->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pCircuitArc->GetColorR()*255), (long)(pCircuitArc->GetColorG()*255), (long)(pCircuitArc->GetColorB()*255));
		pArc->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pArc->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	pArc->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::CreateMatVariant(const double mat[16], VARIANT & var)
{
	if(!mat)
		return false;

	SAFEARRAY *psaValues=NULL;
	SAFEARRAYBOUND rgsabound[2];
	rgsabound[0].lLbound = 0;
	rgsabound[0].cElements = 4;
	rgsabound[1].lLbound = 0;
	rgsabound[1].cElements = 4;
	psaValues = SafeArrayCreate(VT_R8, 2, rgsabound);

	long indice[2];
	for(int i=0; i<4; i++)
	{
		indice[0]=i;
		for(int j=0; j<4; j++)
		{
			indice[1]=j;
			SafeArrayPutElement(psaValues, indice, (void *)&mat[i*4+j]);
		}
	}

	var.vt=VT_ARRAY|VT_R8;
	var.parray=psaValues;

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitLine(IAcadBlock *pBlockDef, CCircuitLine *pCircuitLine, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pCircuitLine->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	long pts_size=6;
	double pts[]={pCircuitLine->GetStartPosX(), pCircuitLine->GetStartPosY(), 0, pCircuitLine->GetEndPosX(), pCircuitLine->GetEndPosY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_FALSE);

	if(pCircuitLine->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(pCircuitLine->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pCircuitLine->GetColorR()*255), (long)(pCircuitLine->GetColorG()*255), (long)(pCircuitLine->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	eLinePattern lp=pCircuitLine->GetLinePattern();
	if(lp==DASH_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);
		if (!pDatabase)
			return false;

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDEN")))
			pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
		//IAcadLineType *pLineType=NULL;
		//pLineTypes->Add(_bstr_t(""), &pLineType);

		//pLineType->get_Description()
		pPolyline->put_Linetype(_bstr_t("HIDDEN"));
		//pPolyline->put_LinetypeScale(0.1);
	}
	else if(lp==DOTTED_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DOT")))
			pLineTypes->Load(_bstr_t("DOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DOT"));
	}
	else if(lp==DASH_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DASHDOT")))
			pLineTypes->Load(_bstr_t("DASHDOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DASHDOT"));
	}
	else if(lp==DASH_DOUBLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DIVIDE")))
			pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DIVIDE"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("ACAD_ISO14W100")))
			pLineTypes->Load(_bstr_t("ACAD_ISO14W100"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("ACAD_ISO14W100"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDENX2")))
			pLineTypes->Load(_bstr_t("HIDDENX2"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("HIDDENX2"));
	}
	else if(lp==CENTER_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("CENTER")))
			pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("CENTER"));
	}
	else if(lp==PHANTOM_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("PHANTOM")))
			pLineTypes->Load(_bstr_t("PHANTOM"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("PHANTOM"));
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	pPolyline->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPolyline(IAcadBlock *pBlockDef, CCircuitPolyline *pCircuitPolyline, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pCircuitPolyline->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	std::list<double> PosList=pCircuitPolyline->GetPosList();
	long lPtSize=PosList.size();
	long pts_size=(long(lPtSize/2))*3;
	double * pts=new double[pts_size];

	std::list<double>::const_iterator iter;
	int i=0;
	for(iter=PosList.begin(); iter!=PosList.end() && i<pts_size; ++iter)
	{
		pts[i]=*iter;
		i++;

		if((i+1)%3==0)
		{
			pts[i]=0;
			i++;
		}
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_FALSE);

	if(pCircuitPolyline->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(pCircuitPolyline->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pCircuitPolyline->GetColorR()*255), (long)(pCircuitPolyline->GetColorG()*255), (long)(pCircuitPolyline->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	eLinePattern lp=pCircuitPolyline->GetLinePattern();
	if(lp==DASH_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDEN")))
			pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
		//IAcadLineType *pLineType=NULL;
		//pLineTypes->Add(_bstr_t(""), &pLineType);

		//pLineType->get_Description()
		pPolyline->put_Linetype(_bstr_t("HIDDEN"));
		//pPolyline->put_LinetypeScale(0.1);
	}
	else if(lp==DOTTED_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DOT")))
			pLineTypes->Load(_bstr_t("DOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DOT"));
	}
	else if(lp==DASH_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DASHDOT")))
			pLineTypes->Load(_bstr_t("DASHDOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DASHDOT"));
	}
	else if(lp==DASH_DOUBLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DIVIDE")))
			pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DIVIDE"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("ACAD_ISO14W100")))
			pLineTypes->Load(_bstr_t("ACAD_ISO14W100"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("ACAD_ISO14W100"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDENX2")))
			pLineTypes->Load(_bstr_t("HIDDENX2"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("HIDDENX2"));
	}
	else if(lp==CENTER_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("CENTER")))
			pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("CENTER"));
	}
	else if(lp==PHANTOM_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		pBlockDef->get_Database(&pDatabase);

		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("PHANTOM")))
			pLineTypes->Load(_bstr_t("PHANTOM"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("PHANTOM"));
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	pPolyline->Release();

	delete []pts;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPolygon(IAcadBlock *pBlockDef, CCircuitPolygon *pCircuitPolygon, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pCircuitPolygon->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	std::list<double> PosList=pCircuitPolygon->GetPtPosList();
	long lPtSize=PosList.size();
	long pts_size=(long(lPtSize/2))*3;
	double * pts=new double[pts_size];

	std::list<double>::const_iterator iter;
	int i=0;
	for(iter=PosList.begin(); iter!=PosList.end() && i<pts_size; ++iter)
	{
		pts[i]=*iter;
		i++;

		if((i+1)%3==0)
		{
			pts[i]=0;
			i++;
		}
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_TRUE);

	if(pCircuitPolygon->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(pCircuitPolygon->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pCircuitPolygon->GetBorderColorR()*255), (long)(pCircuitPolygon->GetBorderColorG()*255), (long)(pCircuitPolygon->GetBorderColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	if(pCircuitPolygon->IsFill())
	{
		IAcadHatch *pHatch=NULL;
		pBlockDef->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
		if(pHatch)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pCircuitPolygon->GetFillColorR()*255), (long)(pCircuitPolygon->GetFillColorG()*255), (long)(pCircuitPolygon->GetFillColorB()*255));
				pHatch->put_TrueColor(pColor);
				pColor->Release();
			}

			COleSafeArray saLoop;
			//IDispatch * ent_array[]={pPolyline};
			saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
			VARIANT * pvLoop=(LPVARIANT)saLoop;

			pHatch->AppendOuterLoop(*pvLoop);

			pHatch->Release();
		}
	}
	else
		pPolyline->Release();

	delete []pts;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitRect(IAcadBlock *pBlockDef, CCircuitRectangle *pRect, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pRect->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	long pts_size=12;
	double pts[]={	pRect->GetStartPosX(), pRect->GetStartPosY(), 0,
		pRect->GetEndPosX(), pRect->GetStartPosY(), 0,
		pRect->GetEndPosX(), pRect->GetEndPosY(), 0,
		pRect->GetStartPosX(), pRect->GetEndPosY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_TRUE);

	if(pRect->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(pRect->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pRect->GetBorderColorR()*255), (long)(pRect->GetBorderColorG()*255), (long)(pRect->GetBorderColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	if(pRect->IsFill())
	{
		IAcadHatch *pHatch=NULL;
		pBlockDef->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
		if(pHatch)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pRect->GetFillColorR()*255), (long)(pRect->GetFillColorG()*255), (long)(pRect->GetFillColorB()*255));
				pHatch->put_TrueColor(pColor);
				pColor->Release();
			}

			COleSafeArray saLoop;
			//IDispatch * ent_array[]={pPolyline};
			saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
			VARIANT * pvLoop=(LPVARIANT)saLoop;

			pHatch->AppendOuterLoop(*pvLoop);

			pHatch->Release();
		}
	}
	else
		pPolyline->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitEllipse(IAcadBlock *pBlockDef, CCircuitEllipse *pCircuitEllipse, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pCircuitEllipse->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	long pts_size=3;
	double pts[]={pCircuitEllipse->GetPosX(), pCircuitEllipse->GetPosY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	pts[0]=pCircuitEllipse->GetRadiusX();
	pts[1]=0;

	COleSafeArray major;
	major.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvMajor =  (LPVARIANT)major;

	double dblRatio=pCircuitEllipse->GetRadiusY()/pCircuitEllipse->GetRadiusX();
	//dsj 20190720 椭圆离心率在0~1之间，否则会失败
	if (dblRatio > 1)
		dblRatio = 1/dblRatio;

	IAcadEllipse *pEllipse=NULL;
	pBlockDef->AddEllipse(*pvPts, *pvMajor, dblRatio, &pEllipse);
	//if(pEllipse->GetBorderWidth()>1.0001)
	//	pEllipse->put_ConstantWidth(pRect->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同
	if (!pEllipse)
	{
		return false;
	}
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pCircuitEllipse->GetBorderColorR()*255), (long)(pCircuitEllipse->GetBorderColorG()*255), (long)(pCircuitEllipse->GetBorderColorB()*255));
		pEllipse->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pEllipse->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	if(pCircuitEllipse->IsFill())
	{
		IAcadHatch *pHatch=NULL;
		pBlockDef->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
		if(pHatch)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pCircuitEllipse->GetFillColorR()*255), (long)(pCircuitEllipse->GetFillColorG()*255), (long)(pCircuitEllipse->GetFillColorB()*255));
				pHatch->put_TrueColor(pColor);
				pColor->Release();
			}

			COleSafeArray saLoop;
			//IDispatch * ent_array[]={pPolyline};
			saLoop.CreateOneDim(VT_DISPATCH, 1, &pEllipse);
			VARIANT * pvLoop=(LPVARIANT)saLoop;

			pHatch->AppendOuterLoop(*pvLoop);

			pHatch->Release();
		}
	}
	else
		pEllipse->Release();

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitEllipseArc(IAcadBlock *pBlockDef, CCircuitEllipseArc *pCircuitEllipseArc, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pCircuitEllipseArc->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	long pts_size=3;
	double pts[]={pCircuitEllipseArc->GetPosX(), pCircuitEllipseArc->GetPosY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	double dblRatio=pCircuitEllipseArc->GetRadiusY()/pCircuitEllipseArc->GetRadiusX();

	bool bXAxis = true;


	IAcadEllipse *pEllipse=NULL;
	if( dblRatio >1 )
	{
		bXAxis = false;
		dblRatio=pCircuitEllipseArc->GetRadiusX()/pCircuitEllipseArc->GetRadiusY();

		pts[0]=0;
		pts[1]=pCircuitEllipseArc->GetRadiusY();


	}
	else
	{
		bXAxis = true; 
		pts[0]=pCircuitEllipseArc->GetRadiusX();
		pts[1]=0;

	}

	COleSafeArray major;
	major.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvMajor =  (LPVARIANT)major;

	pBlockDef->AddEllipse(*pvPts, *pvMajor, dblRatio, &pEllipse);
	//if(pEllipse->GetBorderWidth()>1.0001)
	//	pEllipse->put_ConstantWidth(pRect->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同
	if (pEllipse)  //0717;
	{
		if (abs(pCircuitEllipseArc->GetEndAngle()-pCircuitEllipseArc->GetStartAngle()) >= 0.001 )
		{
			if( bXAxis )
			{
				pEllipse->put_StartAngle(pCircuitEllipseArc->GetStartAngle()*PI/180.0);
				pEllipse->put_EndAngle(pCircuitEllipseArc->GetEndAngle()*PI/180.0);
			}
			else
			{
				pEllipse->put_StartAngle((pCircuitEllipseArc->GetStartAngle()-90)*PI/180.0);
				pEllipse->put_EndAngle((pCircuitEllipseArc->GetEndAngle()-90)*PI/180.0);
			}
		}

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pCircuitEllipseArc->GetColorR()*255), (long)(pCircuitEllipseArc->GetColorG()*255), (long)(pCircuitEllipseArc->GetColorB()*255));
			pEllipse->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pEllipse->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}
	}	


	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPowerPort(IAcadBlock *pBlockDef, CCircuitPowerPort *pPowerPort, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pPowerPort->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblRotateAngle=pPowerPort->GetRotateAngle()*PI/180.0;
	double dblPosX=pPowerPort->GetPosX();
	double dblPosY=pPowerPort->GetPosY();

	CTransform translate=CTransform::translate(dblPosX, dblPosY, 0);
	CTransform rotate=CTransform::rotate(dblRotateAngle, 0, 0, 1);
	CTransform ts=rotate*translate;

	double ts_form[16];
	ts.GetDataInColFirst(ts_form);
	VARIANT vtTsForm;
	CreateMatVariant(ts_form, vtTsForm);

	eRotateType rotType = pPowerPort->GetRotateType();
	ePowerPortType type = pPowerPort->GetPowerPortType();
	if(type==POWER_OBJECT_CIRCLE)
	{
		double pts1[]={0, 0, 0, 4, 0, 0};
		ExportLine(pBlockDef, pts1, 0.4, pPowerPort->GetColorR(), pPowerPort->GetColorG(), pPowerPort->GetColorB(), vtTsForm, mat);

		//HPoint center, major, minor;
		//center.x=7; center.y=0; center.z=0;
		//major.x=10; major.y=0; major.z=0;
		//minor.x=7; minor.y=3; minor.z=0;
		//HC_Insert_Elliptical_Arc(&center, &major, &minor, 0, 1);
		long pts_size=3;
		double pts[]={7, 0, 0};

		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvPts =  (LPVARIANT)saPts;     

		pts[0]=3;
		pts[1]=0;

		COleSafeArray major;
		major.CreateOneDim(VT_R8, pts_size, pts);        
		VARIANT * pvMajor =  (LPVARIANT)major;

		double dblRatio=1;

		IAcadEllipse *pEllipse=NULL;
		pBlockDef->AddEllipse(*pvPts, *pvMajor, dblRatio, &pEllipse);
		//if(pEllipse->GetBorderWidth()>1.0001)
		//pEllipse->put_ConstantWidth(0.4);//HOOPS与ACAD中宽度的显示效果不同
		pEllipse->TransformBy(vtTsForm);

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pPowerPort->GetColorR()*255), (long)(pPowerPort->GetColorG()*255), (long)(pPowerPort->GetColorB()*255));
			pEllipse->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pEllipse->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}

		CCircuitPart *pPart = (CCircuitPart *)pPowerPort->GetParentEntity();
		CString strFontName=_T("Times New Roman");
		double dblTextSize=6.0;
		CCircuitFont *pFont = new CCircuitFont();//pPart->GetFont();
		if(pFont)
		{
			strFontName=pFont->GetFontName();
			dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
		}
		delete pFont;

		ExportText(pBlockDef, 10, 0, 0, pPowerPort->GetLabel(), pPowerPort->GetRotateAngle(), strFontName, dblTextSize, pPowerPort->GetColorR(), pPowerPort->GetColorG(), pPowerPort->GetColorB(), vtTsForm, mat);
		//HC_Insert_Text_With_Encoding(10, 0, 0, "wcs", pCirPoPort->GetLabel());
	}
	else if(type==POWER_OBJECT_ARROW)
	{
		double pts1[]={0, 0, 0, 4, 0, 0};
		ExportLine(pBlockDef, pts1, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);

		//画三角形
		double pts2[]={4, -3, 0, 4, 3, 0};
		ExportLine(pBlockDef, pts2, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts3[]={4, -3, 0, 10, 0, 0};
		ExportLine(pBlockDef, pts3, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts4[]={10, 0 , 0, 4, 3, 0};
		ExportLine(pBlockDef, pts4, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);

		CCircuitPart *pPart = (CCircuitPart *)pPowerPort->GetParentEntity();
		CString strFontName=_T("Times New Roman");
		double dblTextSize=6.0;
		CCircuitFont *pFont = new CCircuitFont();//pPart->GetFont();
		if(pFont)
		{
			strFontName=pFont->GetFontName();
			dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
		}
		delete pFont;

		ExportText(pBlockDef, 10, 0, 0, pPowerPort->GetLabel(), pPowerPort->GetRotateAngle(), strFontName, dblTextSize, pPowerPort->GetColorR(), pPowerPort->GetColorG(), pPowerPort->GetColorB(), vtTsForm, mat);
		//HC_Insert_Text_With_Encoding(10, 0, 0, "wcs", pCirPoPort->GetLabel());
	}
	else if(type==POWER_OBJECT_BAR)
	{
		double pts1[]={0, 0, 0, 10, 0, 0};
		ExportLine(pBlockDef, pts1, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts2[]={10, -5, 0, 10, 5, 0};
		ExportLine(pBlockDef, pts2, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);

		CCircuitPart *pPart = (CCircuitPart *)pPowerPort->GetParentEntity();
		CString strFontName=_T("Times New Roman");
		double dblTextSize=6.0;
		CCircuitFont *pFont = new CCircuitFont();//pPart->GetFont();
		if(pFont)
		{
			strFontName=pFont->GetFontName();
			dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
		}
		delete pFont;

		ExportText(pBlockDef, 10, 0, 0, pPowerPort->GetLabel(), 0/*pPowerPort->GetRotateAngle()*/, strFontName, dblTextSize, pPowerPort->GetColorR(), pPowerPort->GetColorG(), pPowerPort->GetColorB(), vtTsForm, mat);
		//HC_Insert_Text_With_Encoding(10, 0, 0, "wcs", pCirPoPort->GetLabel());
	}
	else if(type==POWER_OBJECT_WAVE)
	{
		double pts1[]={0, 0, 0, 6, 0, 0};
		ExportLine(pBlockDef, pts1, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);

		double pts2[]={
			2, 4, 0,
			4, 3, 0,
			6, 0, 0,
			8, -3, 0,
			10, -4, 0
		};
		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, 15, pts2);        
		VARIANT * pvPts =  (LPVARIANT)saPts;     

		IAcadPolyline *pPolyline=NULL;
		pBlockDef->AddPolyline(*pvPts, &pPolyline);
		pPolyline->put_Closed(VARIANT_FALSE);
		//if(pRect->GetBorderWidth()>1.0001)
		pPolyline->put_ConstantWidth(0.4);//pRect->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同
		pPolyline->TransformBy(vtTsForm);

		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pDisplayObj->GetColorR()*255), (long)(pDisplayObj->GetColorG()*255), (long)(pDisplayObj->GetColorB()*255));
			pPolyline->put_TrueColor(pColor);
			pColor->Release();
		}

		if(mat)
		{
			VARIANT vtMat;
			CreateMatVariant(mat, vtMat);
			pPolyline->TransformBy(vtMat);
			::VariantClear(&vtMat);
			//pPolyline->Update();
		}

		pPolyline->Release();

		CCircuitPart *pPart = (CCircuitPart *)pPowerPort->GetParentEntity();
		CString strFontName=_T("Times New Roman");
		double dblTextSize=6.0;
		CCircuitFont *pFont = new CCircuitFont();//pPart->GetFont();
		if(pFont)
		{
			strFontName=pFont->GetFontName();
			dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
		}
		delete pFont;

		ExportText(pBlockDef, 10, 0, 0, pPowerPort->GetLabel(), pPowerPort->GetRotateAngle(), strFontName, dblTextSize, pPowerPort->GetColorR(), pPowerPort->GetColorG(), pPowerPort->GetColorB(), vtTsForm, mat);
		//HC_Insert_Text_With_Encoding(10, 0, 0, "wcs", pCirPoPort->GetLabel());
	}
	else if(type==POWER_OBJECT_POWER_GROUND)
	{
		double pts1[]={0, 0, 0, 10, 0, 0};
		ExportLine(pBlockDef, pts1, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts2[]={10, -10, 0, 10, 10, 0};
		ExportLine(pBlockDef, pts2, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts3[]={13, -7, 0, 13, 7, 0};
		ExportLine(pBlockDef, pts3, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts4[]={16, -4, 0, 16, 4, 0};
		ExportLine(pBlockDef, pts4, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts5[]={19, -1, 0, 19, 1, 0};
		ExportLine(pBlockDef, pts5, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
	}
	else if(type==POWER_OBJECT_SIGNAL_GROUND)
	{
		double pts1[]={0, 0, 0, 10, 0, 0};
		ExportLine(pBlockDef, pts1, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts2[]={10, -10, 0, 10, 10, 0};
		ExportLine(pBlockDef, pts2, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts3[]={10, -10, 0, 20, 0, 0};
		ExportLine(pBlockDef, pts3, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts4[]={20, 0, 0, 10, 10, 0};
		ExportLine(pBlockDef, pts4, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
	}
	else if(type==POWER_OBJECT_EARTH)
	{
		double pts1[]={0, 0, 0, 10, 0, 0};
		ExportLine(pBlockDef, pts1, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts2[]={10, -10, 0, 10, 10, 0};
		ExportLine(pBlockDef, pts2, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts3[]={10, 10, 0, 20, 5, 0};
		ExportLine(pBlockDef, pts3, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts4[]={10, 0, 0, 20, -5, 0};
		ExportLine(pBlockDef, pts4, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
		double pts5[]={10, -10, 0, 20, -15, 0};
		ExportLine(pBlockDef, pts5, 0.4, pDisplayObj->GetColorR(), pDisplayObj->GetColorG(), pDisplayObj->GetColorB(), vtTsForm, mat);
	}

	::VariantClear(&vtTsForm);

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitBusEntry(IAcadBlock *pBlockDef, CCircuitBusEntry * pBusEntry, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	double pts[]={pBusEntry->GetStartPosX(), pBusEntry->GetStartPosY(), 0, pBusEntry->GetEndPosX(), pBusEntry->GetEndPosY(), 0};
	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 6, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	if (!pPolyline)
	{
		return false;
	}
	if(pBusEntry->GetLineWidth()>1.0001)
		pPolyline->put_ConstantWidth(pBusEntry->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pBusEntry->GetColorR()*255), (long)(pBusEntry->GetColorG()*255), (long)(pBusEntry->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	pPolyline->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitJunction(IAcadBlock *pBlockDef, CCircuitJunction *pJunction, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pJunction->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	long pts_size=3;
	double pts[]={pJunction->GetPosX(), pJunction->GetPosY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadCircle *pCircle=NULL;
	pBlockDef->AddCircle(*pvPts, pJunction->GetRadius(), &pCircle);
	//if(pRect->GetBorderWidth()>1.0001)
	//	pPolyline->put_ConstantWidth(pRect->GetBorderWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同
	if (!pCircle)
	{
		return false;
	}
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pJunction->GetColorR()*255), (long)(pJunction->GetColorG()*255), (long)(pJunction->GetColorB()*255));
		pCircle->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pCircle->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	IAcadHatch *pHatch=NULL;
	pBlockDef->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pJunction->GetColorR()*255), (long)(pJunction->GetColorG()*255), (long)(pJunction->GetColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}

		COleSafeArray saLoop;
		//IDispatch * ent_array[]={pPolyline};
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pCircle);
		VARIANT * pvLoop=(LPVARIANT)saLoop;

		pHatch->AppendOuterLoop(*pvLoop);

		pHatch->Release();
	}

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitRoundRect(IAcadBlock *pBlockDef, CCircuitRoundRect *pRoundRect, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pRoundRect->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblCenterX=0.5*(pRoundRect->GetStartPosX()+pRoundRect->GetEndPosX());
	double dblCenterY=0.5*(pRoundRect->GetStartPosY()+pRoundRect->GetEndPosY());
	double dblHalfWidth=0.5*(pRoundRect->GetEndPosX()-pRoundRect->GetStartPosX());
	double dblHalfHeight=0.5*(pRoundRect->GetEndPosY()-pRoundRect->GetStartPosY());

	double dblRadius =min(pRoundRect->GetRadiusX(), pRoundRect->GetRadiusY());
	double pts[]={	dblCenterX-dblHalfWidth+dblRadius, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth-dblRadius, dblCenterY-dblHalfHeight, 0,
		dblCenterX+dblHalfWidth, dblCenterY-dblHalfHeight+dblRadius, 0,
		dblCenterX+dblHalfWidth, dblCenterY+dblHalfHeight-dblRadius, 0,
		dblCenterX+dblHalfWidth-dblRadius, dblCenterY+dblHalfHeight, 0,
		dblCenterX-dblHalfWidth+dblRadius, dblCenterY+dblHalfHeight, 0,
		dblCenterX-dblHalfWidth, dblCenterY+dblHalfHeight-dblRadius, 0,
		dblCenterX-dblHalfWidth, dblCenterY-dblHalfHeight+dblRadius, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 24, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_TRUE);

	//pPolyline->put_ConstantWidth(0.25);
	double dblBulge=tan(PI*0.125);
	pPolyline->SetBulge(1, dblBulge);
	pPolyline->SetBulge(3, dblBulge);
	pPolyline->SetBulge(5, dblBulge);
	pPolyline->SetBulge(7, dblBulge);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pRoundRect->GetBorderColorR()*255), (long)(pRoundRect->GetBorderColorG()*255), (long)(pRoundRect->GetBorderColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	if(pRoundRect->IsFill())
	{
		IAcadHatch *pHatch=NULL;
		pBlockDef->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
		if(pHatch)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pRoundRect->GetFillColorR()*255), (long)(pRoundRect->GetFillColorG()*255), (long)(pRoundRect->GetFillColorB()*255));
				pHatch->put_TrueColor(pColor);
				pColor->Release();
			}

			COleSafeArray saLoop;
			//IDispatch * ent_array[]={pPolyline};
			saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
			VARIANT * pvLoop=(LPVARIANT)saLoop;

			pHatch->AppendOuterLoop(*pvLoop);

			pHatch->Release();
		}
	}
	else
		pPolyline->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitTextFrame(IAcadBlock *pBlockDef, CCircuitTextFrame *pTextFrame, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pTextFrame->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj);

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitNetLabel(IAcadBlock *pBlockDef, CCircuitNetLabel *pNetLabel, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pNetLabel->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	CString szContent = pNetLabel->GetLable();
	double posX = pNetLabel->GetPosX();
	double posY = pNetLabel->GetPosY();
	CCircuitFont *pFont = pNetLabel->GetFont();

	CString strFontName=pFont->GetFontName();

	//double dScaleRatio = 0.02;
	//pCircuitDispObj->GetScaleRatio(dScaleRatio);
	double dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc

	//设置文字方向和旋转角度
	double dblRotateAngleInDegree = pNetLabel->GetRotateAngle();
	double dblRotateAngle=dblRotateAngleInDegree*PI/180.0;

	long pts_size=3;
	double pts[]={posX, posY, 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvInsertPts =  (LPVARIANT)saPts;     

	IAcadText *pText=NULL;
	pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pNetLabel->GetColorR()*255), (long)(pNetLabel->GetColorG()*255), (long)(pNetLabel->GetColorB()*255));
		pText->put_TrueColor(pColor);
		pColor->Release();
	}

	if(fabs(dblRotateAngleInDegree-180)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentRight);

		pText->put_TextAlignmentPoint(*pvInsertPts);
	}
	else if(fabs(dblRotateAngleInDegree)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentLeft);
	}
	else if(fabs(dblRotateAngleInDegree-90)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentLeft);
		pText->put_Rotation(PI*0.5);
	}
	else if(fabs(dblRotateAngleInDegree-270)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentRight);
		pText->put_Rotation(PI*0.5);

		pText->put_TextAlignmentPoint(*pvInsertPts);
	}

	CString strTextStyle=GetOrCreateTextStyle(pBlockDef, strFontName);
	if(!strTextStyle.IsEmpty())
		pText->put_StyleName(_bstr_t(strTextStyle));

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pText->TransformBy(vtMat);
		::VariantClear(&vtMat);
	}

	pText->Release();

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitNoERC(IAcadBlock *pBlockDef, CCircuitNoERC *pNoERC, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pNoERC->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblPosX = pNoERC->GetPosX();
	double dblPosY = pNoERC->GetPosY();

	CTransform translate=CTransform::translate(dblPosX, dblPosY, 0);

	double ts_form[16];
	translate.GetDataInColFirst(ts_form);
	VARIANT vtTsForm;
	CreateMatVariant(ts_form, vtTsForm);

	double pts1[6] = {-5,-5,0,5,5,0};
	bool bRet =		ExportLine(pBlockDef,pts1,0.1,pNoERC->GetColorR(),pNoERC->GetColorG(),pNoERC->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;
	double pts2[6] = {-5,5,0,5,-5,0};
	bRet =		ExportLine(pBlockDef,pts2,0.1,pNoERC->GetColorR(),pNoERC->GetColorG(),pNoERC->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitSimProbe(IAcadBlock *pBlockDef, CCircuitSimProbe *pSimProbe, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pSimProbe->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblPosX = pSimProbe->GetPosX();
	double dblPosY = pSimProbe->GetPosY();

	CTransform translate=CTransform::translate(dblPosX, dblPosY, 0);

	double ts_form[16];
	translate.GetDataInColFirst(ts_form);
	VARIANT vtTsForm;
	CreateMatVariant(ts_form, vtTsForm);

	double pts1[6] ={0, 0, 0, 3, 3, 0};
	bool bRet =		ExportLine(pBlockDef,pts1,0.1,pSimProbe->GetColorR(),pSimProbe->GetColorG(),pSimProbe->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;
	double pts2[6] ={3, 3, 0, 8, 8, 0};
	bRet =		ExportLine(pBlockDef,pts2,2,pSimProbe->GetColorR(),pSimProbe->GetColorG(),pSimProbe->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitSimStimulus(IAcadBlock *pBlockDef, CCircuitSimStimulus *pSimStimulus, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pSimStimulus->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblPosX = pSimStimulus->GetPosX();
	double dblPosY = pSimStimulus->GetPosY();

	CTransform translate=CTransform::translate(dblPosX, dblPosY, 0);

	double ts_form[16];
	translate.GetDataInColFirst(ts_form);
	VARIANT vtTsForm;
	CreateMatVariant(ts_form, vtTsForm);

	double pts[8][6] = {
		0, 0, 0,  0, 8, 0,
		0, 8, 0, -2, 8, 0,
		-2, 8, 0, -2, 2, 0,
		-2, 2, 0, -4, 2, 0,
		-4, 2, 0, -4, 8, 0,
		-4, 8, 0, -6, 8, 0,
		-6, 8, 0, -6, 2, 0,
		-6, 2, 0, -8, 2, 0	 };

		for( int i=0;i<8;i++ )
		{
			bool bRet =		ExportLine(pBlockDef,pts[i],0.3,pSimStimulus->GetColorR(),pSimStimulus->GetColorG(),pSimStimulus->GetColorB(),vtTsForm,mat);
			if (!bRet)
				return false;
		}

		return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitSimVector(IAcadBlock *pBlockDef, CCircuitSimVector *pSimVector, long lLayerId, double mat[16])
{
	CDisplayObj *pDisplayObj=pSimVector->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblPosX = pSimVector->GetPosX();
	double dblPosY = pSimVector->GetPosY();

	CTransform translate=CTransform::translate(dblPosX, dblPosY, 0);

	double ts_form[16];
	translate.GetDataInColFirst(ts_form);
	VARIANT vtTsForm;
	CreateMatVariant(ts_form, vtTsForm);

	double pts1[6] ={0, 0, 0, 0, 6, 0};
	bool bRet =		ExportLine(pBlockDef,pts1,0.1,pSimVector->GetColorR(),pSimVector->GetColorG(),pSimVector->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;
	double pts2[6] ={0, 6, 0, -2, 6, 0};
	bRet =		ExportLine(pBlockDef,pts2,0.1,pSimVector->GetColorR(),pSimVector->GetColorG(),pSimVector->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;

	long pts_size=3;
	double pts[]={-6, 6, 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadCircle *pCircle=NULL;
	pBlockDef->AddCircle(*pvPts,4, &pCircle);
	pCircle->TransformBy(vtTsForm);
	//	pCircle->put_Lineweight(AutoCAD::ACAD_LWEIGHT::acLnWt040);
	if(!pCircle)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pSimVector->GetColorR()*255), (long)(pSimVector->GetColorG()*255), (long)(pSimVector->GetColorB()*255));
		pCircle->put_TrueColor(pColor);
		pColor->Release();
	}

	pCircle->Release();

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPCBLayoout(IAcadBlock *pBlockDef, CCircuitLayoutDirective *pLayout, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pLayout->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj)
		return true;

	double dblPosX = pLayout->GetPosX();
	double dblPosY = pLayout->GetPosY();

	CTransform translate=CTransform::translate(dblPosX, dblPosY, 0);

	double ts_form[16];
	translate.GetDataInColFirst(ts_form);
	VARIANT vtTsForm;
	CreateMatVariant(ts_form, vtTsForm);

	double pts1[6] ={0, 0, 0, 0, 6, 0};
	bool bRet =		ExportLine(pBlockDef,pts1,0.3,pLayout->GetColorR(),pLayout->GetColorG(),pLayout->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;
	double pts2[6] ={0, 6, 0, -2, 6, 0};
	bRet =		ExportLine(pBlockDef,pts2,0.3,pLayout->GetColorR(),pLayout->GetColorG(),pLayout->GetColorB(),vtTsForm,mat);
	if (!bRet)
		return false;
	long pts_size=3;
	double pts[]={-6, 6, 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadCircle *pCircle=NULL;
	pBlockDef->AddCircle(*pvPts,4, &pCircle);
	pCircle->TransformBy(vtTsForm);
	if(!pCircle)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pLayout->GetColorR()*255), (long)(pLayout->GetColorG()*255), (long)(pLayout->GetColorB()*255));
		pCircle->put_TrueColor(pColor);
		pColor->Release();
	}

	pCircle->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitBezier(IAcadBlock *pBlockDef, CCircuitBezier *pBezier, long lLayerId, double mat[16])
{
	CDisplayObj *pDisplayObj=pBezier->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj);
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitGraphic(IAcadBlock *pBlockDef, CCircuitGraph *pGraph, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pGraph->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj);
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCircuitUnitPieChart(IAcadBlock *pBlockDef, CCircuitPieChart *pPieChart, long lLayerId, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	CDisplayObj *pDisplayObj=pPieChart->GetDisplayObjByLayerID(lLayerId);
	if(!pDisplayObj);
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportLine(IAcadBlock *pBlockDef, double pts[6], double dblLineWidth, double color_r, double color_g, double color_b, const VARIANT & vtMat1, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 6, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	pBlockDef->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_FALSE);

	//if(pCircuitLine->GetBorderWidth()>1.0001)
	pPolyline->put_ConstantWidth(dblLineWidth);//HOOPS与ACAD中宽度的显示效果不同
	pPolyline->TransformBy(vtMat1);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(color_r*255), (long)(color_g*255), (long)(color_b*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pPolyline->TransformBy(vtMat);
		::VariantClear(&vtMat);
		//pPolyline->Update();
	}

	pPolyline->Release();
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportText(IAcadBlock *pBlockDef, double pos_x, double pos_y, double pos_z, const CString & strText, double dblRotateAngleInDegree, const CString & strFontName, double dblTextSize, double color_r, double color_g, double color_b, const VARIANT & vtMat1, double mat[16])
{
	if (IsStopLayerExport())
		return false;
	//设置文字方向和旋转角度
	double dblRotateAngle=dblRotateAngleInDegree*PI/180.0;

	long pts_size=3;
	double pts[]={pos_x, pos_y, pos_z};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvInsertPts =  (LPVARIANT)saPts;     

	IAcadText *pText=NULL;
	pBlockDef->AddText(_bstr_t(strText), *pvInsertPts, dblTextSize, &pText);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(color_r*255), (long)(color_g*255), (long)(color_b*255));
		pText->put_TrueColor(pColor);
		pColor->Release();
	}

	if(fabs(dblRotateAngleInDegree-180)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentMiddleRight);
		pText->put_TextAlignmentPoint(*pvInsertPts);
	}
	else if(fabs(dblRotateAngleInDegree)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentMiddleLeft);
		pText->put_TextAlignmentPoint(*pvInsertPts);
	}
	else if(fabs(dblRotateAngleInDegree-90)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentMiddleLeft);
		pText->put_Rotation(PI*0.5);

		pText->put_TextAlignmentPoint(*pvInsertPts);
	}
	else if(fabs(dblRotateAngleInDegree-270)<1)
	{
		pText->put_Alignment(AutoCAD::acAlignmentMiddleRight);
		pText->put_Rotation(PI*0.5);

		pText->put_TextAlignmentPoint(*pvInsertPts);
	}
	pText->TransformBy(vtMat1);

	if(fabs(dblRotateAngleInDegree-180)<1 || fabs(dblRotateAngleInDegree)<1)
		pText->put_Rotation(0);
	else if(fabs(dblRotateAngleInDegree-90)<1 || fabs(dblRotateAngleInDegree-270)<1)
		pText->put_Rotation(PI*0.5);

	CString strTextStyle=GetOrCreateTextStyle(pBlockDef, strFontName);
	if(!strTextStyle.IsEmpty())
		pText->put_StyleName(_bstr_t(strTextStyle));

	if(mat)
	{
		VARIANT vtMat;
		CreateMatVariant(mat, vtMat);
		pText->TransformBy(vtMat);
		::VariantClear(&vtMat);
	}

	pText->Release();
	return true;
}

// bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportPartDesignator(IAcadBlock *pBlockDef, CPartDesignator *pPartDesignator)
// {
// 	if (IsStopLayerExport())
// 		return false;
// 	CString szContent=pPartDesignator->GetLable();
// 
// 	CString strFontName=_T("Times New Roman");
// 	double dblTextSize=6.0;
// 	CCircuitFont *pFont = pPartDesignator->GetFont();
// 	if(pFont)
// 	{
// 		strFontName=pFont->GetFontName();
// 		dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
// 	}
// 
// 	long pts_size=3;
// 	double pts[]={pPartDesignator->GetPosX(), pPartDesignator->GetPosY(), 0};
// 
// 	COleSafeArray   saPts;
// 	saPts.CreateOneDim(VT_R8, pts_size, pts);        
// 	VARIANT * pvInsertPts =  (LPVARIANT)saPts;     
// 
// 	IAcadText *pText=NULL;
// 	pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);
// 
// 	IAcadAcCmColor *pColor=GetColor();
// 	if(pColor)
// 	{
// 		pColor->SetRGB((long)(pPartDesignator->GetColorR()*255), (long)(pPartDesignator->GetColorG()*255), (long)(pPartDesignator->GetColorB()*255));
// 		pText->put_TrueColor(pColor);
// 		pColor->Release();
// 	}
// 
// 	CString strTextStyle=GetOrCreateTextStyle(pBlockDef, strFontName);
// 	if(!strTextStyle.IsEmpty())
// 		pText->put_StyleName(_bstr_t(strTextStyle));
// 
// 	pText->Release();
// 	return true;
// }

//dsj 20190720

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportPartDesignator(IAcadBlock *pBlockDef, CPartDesignator *pPartDesignator, bool bIsDsnPart/* = false*/, pair<double, double> pParentPos/* = pair<double, double>(0,0)*/)
{
	if (IsStopLayerExport())
		return false;

	//font
	CString strFontName=_T("Times New Roman");
	double dblTextSize=6.0;
	CCircuitFont *pFont = pPartDesignator->GetFont();
	if(pFont)
	{
		strFontName=pFont->GetFontName();
		dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
	}

	//text style
	CString strTextStyle = GetOrCreateTextStyle(pBlockDef, strFontName);

	CString szContent = pPartDesignator->GetLable();
	string strText = CStringToStdstringUTF8(szContent);
	double dOffset = 2.0;
	double dbY = -10;

	vector<string> vecTexts = GetDataVectorFromStringBySeparator( strText, STR_FIELDS );
	for ( vector<string>::iterator iterText = vecTexts.begin(); iterText != vecTexts.end(); ++iterText )
	{
		string strField = *iterText;
		string sValue = "";
		vector<string> vecName2Val = GetDataVectorFromStringBySeparator( strField, STR_NAME2VALUE );
		if ( vecName2Val.size() < 1 )
		{
			continue;
		}
		if ( vecName2Val.size() < 2  )
		{
			dbY = 0;
		}
		string strName = vecName2Val.front();
		if ( strName == "Name")
		{
			continue;
		}
		sValue = vecName2Val.back();
		bool bShow = true;
		if ( vecName2Val.size() > 2)
		{
			string sShow = vecName2Val[ 2 ];
			bShow = (sShow == "1");
			sValue = vecName2Val[ 1 ];
		}
		if ( !bShow )
		{
			continue;
		}

		CString csOneFieldVal ;
		StdstringUTF8ToCString( sValue, csOneFieldVal );
		
		long pts_size=3;
		double x = bIsDsnPart ? pParentPos.first : pPartDesignator->GetPosX();
		double y = bIsDsnPart ? (dOffset - dbY + pParentPos.second) : pPartDesignator->GetPosY();
		double pts[]={x, y, 0};
		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, pts_size, pts);
		VARIANT * pvInsertPts =  (LPVARIANT)saPts;

		IAcadText *pText=NULL;
		pBlockDef->AddText(_bstr_t(csOneFieldVal), *pvInsertPts, dblTextSize, &pText);

		IAcadAcCmColor *pColor = GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pPartDesignator->GetColorR()*255), (long)(pPartDesignator->GetColorG()*255), (long)(pPartDesignator->GetColorB()*255));
			pText->put_TrueColor(pColor);
			pColor->Release();
		}
		if(!strTextStyle.IsEmpty())
			pText->put_StyleName(_bstr_t(strTextStyle));
		pText->Release();
		dbY += 10;
	}

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportMentorPartDesignator(IAcadBlock *pBlockDef, CPartDesignator *pPartDesignator, const CTransform& transform)
{
	if (IsStopLayerExport())
		return false;

	//font
	CString strFontName=_T("Times New Roman");
	double dblTextSize=6.0;
	CCircuitFont *pFont = pPartDesignator->GetFont();
	if(pFont)
	{
		strFontName=pFont->GetFontName();
		dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
	}
	CString strTextStyle = GetOrCreateTextStyle(pBlockDef, strFontName);

	//content
	CString szContent = pPartDesignator->GetLable();

	//position
	CPos position(pPartDesignator->GetPosX(), pPartDesignator->GetPosY(), 0);
	position = transform.TransformPos(position);
	double pts[] = { position.GetPosX(), position.GetPosY(), 0};
	long pts_size = 3;
	COleSafeArray saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);
	VARIANT * pvInsertPts =  (LPVARIANT)saPts;

	IAcadText *pText=NULL;
	pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);

	IAcadAcCmColor *pColor = GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pPartDesignator->GetColorR()*255), (long)(pPartDesignator->GetColorG()*255), (long)(pPartDesignator->GetColorB()*255));
		pText->put_TrueColor(pColor);
		pColor->Release();
	}
	if(!strTextStyle.IsEmpty())
		pText->put_StyleName(_bstr_t(strTextStyle));
	pText->Release();

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportAltiumCircuitPartParam(IAcadBlock *pBlockDef, CAltiumCircuitParam* pParam)
{
	if (IsStopLayerExport())
		return false;
	
	//font
	CString strFontName=_T("Times New Roman");
	double dblTextSize=6.0;
	CCircuitFont *pFont = pParam->GetFont();
	if(pFont)
	{
		strFontName=pFont->GetFontName();
		dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
	}

	//text style
	CString strTextStyle = GetOrCreateTextStyle(pBlockDef, strFontName);

	CString szContent = pParam->GetValue();
	string strText = CStringToStdstringUTF8(szContent);
	
	long pts_size=3;
	double pts[]={pParam->GetPosX(), pParam->GetPosY(), 0};
	COleSafeArray saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);
	VARIANT * pvInsertPts =  (LPVARIANT)saPts;

	IAcadText *pText=NULL;
	pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);

	IAcadAcCmColor *pColor = GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pParam->GetFontColorR()*255), (long)(pParam->GetFontColorG()*255), (long)(pParam->GetFontColorB()*255));
		pText->put_TrueColor(pColor);
		pColor->Release();
	}
	if(!strTextStyle.IsEmpty())
		pText->put_StyleName(_bstr_t(strTextStyle));
	pText->Release();

	return true;
}

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportTinyCADCircuitPartParam(IAcadBlock *pBlockDef, CTinyCADParam* pParam)
{
	if (IsStopLayerExport())
		return false;

	//font
	CString strFontName=_T("Times New Roman");
	double dblTextSize=6.0;
	CCircuitFont *pFont = pParam->GetFont();
	if(pFont)
	{
		strFontName=pFont->GetFontName();
		dblTextSize = pFont->GetSize()*0.6; //为什么字高要乘以0.6适合，暂时没弄明白！zxc
	}

	//text style
	CString strTextStyle = GetOrCreateTextStyle(pBlockDef, strFontName);

	CString szContent = pParam->GetValue();
	string strText = CStringToStdstringUTF8(szContent);

	long pts_size=3;
	double pts[]={pParam->GetPosX(), pParam->GetPosY(), 0};
	COleSafeArray saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);
	VARIANT * pvInsertPts =  (LPVARIANT)saPts;

	IAcadText *pText=NULL;
	pBlockDef->AddText(_bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);

	IAcadAcCmColor *pColor = GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pParam->GetFontColorR()*255), (long)(pParam->GetFontColorG()*255), (long)(pParam->GetFontColorB()*255));
		pText->put_TrueColor(pColor);
		pColor->Release();
	}
	if(!strTextStyle.IsEmpty())
		pText->put_StyleName(_bstr_t(strTextStyle));
	pText->Release();

	return true;
}

#ifndef OVERWRITE_FUNCTION_GetColor
IAcadAcCmColor * ACAD_EXPORT_TOOL_COMMON_IMPL::GetColor() const
{
	IDispatch *disp=NULL;
	HRESULT hr=m_pAcadApp->GetInterfaceObject(_bstr_t("AutoCAD.AcCmColor.17"), &disp);//acad2008
	if(FAILED(hr))
	{
		hr=m_pAcadApp->GetInterfaceObject(_bstr_t("AutoCAD.AcCmColor.18"), &disp);//2012
		if(FAILED(hr))
		{
			hr=m_pAcadApp->GetInterfaceObject(_bstr_t("AutoCAD.AcCmColor.19"), &disp);
			if(FAILED(hr))
			{
				hr=m_pAcadApp->GetInterfaceObject(_bstr_t("AutoCAD.AcCmColor.20"), &disp);
			}
		}
	}

	if(!disp)
		return NULL;

	IAcadAcCmColor *pColor=NULL;
	const GUID IID_AcCmColor_17 = {0x7382f647,0xbc48,0x456e,{0xb8,0x77,0xd1,0x8f,0x58,0xbe,0x68,0x78}};
	disp->QueryInterface(IID_AcCmColor_17, (void **)&pColor);
	if(!pColor)
	{
		const GUID IID_AcCmColor_18 = {0xa3fe9168,0x5dea,0x45a8,{0xb4,0x7b,0x3f,0xc7,0xe8,0x40,0x7b,0x94}};//2012
		disp->QueryInterface(IID_AcCmColor_18, (void **)&pColor);
	}

	if(pColor)
		pColor->put_ColorMethod(AutoCAD::acColorMethodByRGB);
	disp->Release();

	return pColor;
}
#endif //!OVERWRITE_FUNCTION_GetColor


CString ACAD_EXPORT_TOOL_COMMON_IMPL::GetOrCreateTextStyle(IAcadBlock *pBlock, const CString & strFont) const
{
	if(!pBlock)
		return _T("");

	IAcadDatabase *pDatabase=NULL;
	pBlock->get_Database(&pDatabase);
	if(!pDatabase )\
		return _T("");
	CString strTextStyle=GetOrCreateTextStyle(pDatabase, strFont);

	pDatabase->Release();

	return strTextStyle;
}


CString ACAD_EXPORT_TOOL_COMMON_IMPL::GetOrCreateTextStyle(IAcadModelSpace *pModelSpace, const CString & strFont) const
{
	if(!pModelSpace)
		return false;
	IAcadDatabase *pDatabase=NULL;
	m_pModelSpace->get_Database(&pDatabase);

	CString strTextStyle=GetOrCreateTextStyle(pDatabase, strFont);

	pDatabase->Release();

	return strTextStyle;

	//IAcadTextStyles *pTextStyles=NULL;
	//pDatabase->get_TextStyles(&pTextStyles);

	//long lCount=0;
	//pTextStyles->get_Count(&lCount);

	//for(long i=0; i<lCount; i++)
	//{
	//	IAcadTextStyle *pTextStyle=NULL;
	//	pTextStyles->Item(_variant_t(i), &pTextStyle);

	//	if(pTextStyle)
	//	{
	//		BSTR bstrFaceType;
	//		VARIANT_BOOL bBold, bItalic;
	//		long lCharset, lPitchAndFamily;
	//		pTextStyle->GetFont(&bstrFaceType, &bBold, &bItalic, &lCharset, &lPitchAndFamily);
	//		if(strFont.Compare(bstrFaceType)==0)
	//		{
	//			BSTR bstrName;
	//			pTextStyle->get_Name(&bstrName);

	//			pTextStyle->Release();
	//			pTextStyles->Release();

	//			return CString(bstrName);
	//		}

	//		pTextStyle->Release();
	//	}
	//}

	//IAcadTextStyle *pTextStyle=NULL;
	//pTextStyles->Add(_bstr_t(strFont), &pTextStyle);
	//if(pTextStyle)
	//{
	//	CString strFontName(strFont);
	//	int nIndex=strFont.Find(_T('-'));//可能是“楷体-GDI-VECTOR”形式
	//	if(nIndex!=-1)
	//		strFontName=strFontName.Left(nIndex);

	//	pTextStyle->SetFont(_bstr_t(strFontName), VARIANT_FALSE, VARIANT_FALSE, DEFAULT_CHARSET, DEFAULT_PITCH|FF_SWISS);
	//	//pTextStyle->put_Width(0.707);
	//	pTextStyle->Release();

	//	return strFont;
	//}

	//pTextStyles->Release();

	//return _T("");
}


CString ACAD_EXPORT_TOOL_COMMON_IMPL::GetOrCreateTextStyle(IAcadDatabase *pDatabase, const CString & strFont) const
{
	if (!pDatabase)
		return _T("");
	IAcadTextStyles *pTextStyles=NULL;
	pDatabase->get_TextStyles(&pTextStyles);
	long lCount=0;
	pTextStyles->get_Count(&lCount);

	for(long i=0; lCount > 0 && i<lCount; i++)
	{
		IAcadTextStyle *pTextStyle=NULL;
		pTextStyles->Item(_variant_t(i), &pTextStyle);

		if(pTextStyle)
		{
			BSTR bstrFaceType;
			VARIANT_BOOL bBold, bItalic;
			long lCharset, lPitchAndFamily;
			pTextStyle->GetFont(&bstrFaceType, &bBold, &bItalic, &lCharset, &lPitchAndFamily);
			if(strFont.Compare(bstrFaceType)==0)
			{
				BSTR bstrName;
				pTextStyle->get_Name(&bstrName);

				pTextStyle->Release();
				pTextStyles->Release();

				return CString(bstrName);
			}

			pTextStyle->Release();
		}
	}

	IAcadTextStyle *pTextStyle=NULL;
	pTextStyles->Add(_bstr_t(strFont), &pTextStyle);
	if(pTextStyle)
	{
		CString strFontName(strFont);
		int nIndex=strFont.Find(_T('-'));//可能是“楷体-GDI-VECTOR”形式
		if(nIndex!=-1)
			strFontName=strFontName.Left(nIndex);

		pTextStyle->SetFont(_bstr_t(strFontName), VARIANT_FALSE, VARIANT_FALSE, DEFAULT_CHARSET, DEFAULT_PITCH|FF_SWISS);
		//pTextStyle->put_Width(0.707);
		pTextStyle->Release();

		return strFont;
	}

	pTextStyles->Release();

	return _T("");
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExistLineType(IAcadLineTypes *pLineTypes, const CString & strLineType) const
{
	IAcadLineType *pLineType=NULL;
	pLineTypes->Item(_variant_t(strLineType), &pLineType);
	if(pLineType)
	{
		pLineType->Release();
		return true;
	}

	return false;

	//long lCount=0;
	//pLineTypes->get_Count(&lCount);

	//for(long i=0; i<lCount; i++)
	//{
	//	IAcadLineType *pLineType=NULL;
	//	pLineTypes->Item(_variant_t(i), &pLineType);

	//	BSTR bstrName;
	//	pLineType->get_Name(&bstrName);
	//}
}


void ACAD_EXPORT_TOOL_COMMON_IMPL::CountDisplayObj(CSubSystem *pSystem, long & lCount) const
{
	lCount+=pSystem->GetDeviceList().size();

	const std::list<CDevice *> & DeviceList=pSystem->GetDeviceList();
	std::list<CDevice *>::const_iterator it_dev;
	for(it_dev=DeviceList.begin(); it_dev!=DeviceList.end(); ++it_dev)
	{
		lCount+=(*it_dev)->GetDisplayObjList().size();

		std::list<CEntityObj *> CircuitList;
		(*it_dev)->GetICircuitContentList(CircuitList);
		std::list<CEntityObj *>::const_iterator it_c;
		for(it_c=CircuitList.begin(); it_c!=CircuitList.end(); ++it_c)
		{
			if(!(*it_c)->IsICircuit())
				continue;

			CICircuit *pCircuit=(CICircuit *)*it_c;
			lCount+=pCircuit->GetDisplayObjList().size();
		}
	}

	const std::list<CConnector *> & ConnectorList=pSystem->GetConnectorList();
	std::list<CConnector *>::const_iterator it_conn;
	for(it_conn=ConnectorList.begin(); it_conn!=ConnectorList.end(); ++it_conn)
		lCount+=(*it_conn)->GetDisplayObjList().size();

	const std::list<CCable *> & CableList=pSystem->GetCableList();
	std::list<CCable *>::const_iterator it_cable;
	for(it_cable=CableList.begin(); it_cable!=CableList.end(); ++it_cable)
	{
		const std::list<CSubCable *> & SubCableList=(*it_cable)->GetSubCableList();

		long lLayerCount=0;
		if(pSystem->IsSystem())
			lLayerCount=((CSystem *)pSystem)->GetLayerList().size();

		std::list<CSubCable *>::const_iterator it_sc;
		for(it_sc=SubCableList.begin(); it_sc!=SubCableList.end(); ++it_sc)
			lCount+=lLayerCount;
	}

	const std::list<CSubSystem *> & SubSystemList=pSystem->GetSubSystemList();
	std::list<CSubSystem *>::const_iterator it_ss;
	for(it_ss=SubSystemList.begin(); it_ss!=SubSystemList.end(); ++it_ss)
		CountDisplayObj(*it_ss, lCount);
}


void ACAD_EXPORT_TOOL_COMMON_IMPL::CountLayerDisplayObj(CSubSystem *pSystem,CLayer *pLayer,long & lCount)const
{
	long layerId = pLayer->GetId();
	std::list<CDevice *>DeviceList;

	pSystem->GetAllDevices(DeviceList);
	lCount+=DeviceList.size();

	std::list<CDevice *>::const_iterator it_dev;
	for(it_dev=DeviceList.begin(); it_dev!=DeviceList.end(); ++it_dev)
	{		
		CDisplayObj* pDeviceDisObj=(*(*it_dev)).GetDisplayObjByLayerID(layerId);
		if (pDeviceDisObj)
		{
			lCount+=1;
		}
		std::list<CEntityObj *> CircuitList;
		(*it_dev)->GetICircuitContentList(CircuitList);
		std::list<CEntityObj *>::const_iterator it_c;
		for(it_c=CircuitList.begin(); it_c!=CircuitList.end(); ++it_c)
		{
			if(!(*it_c)->IsICircuit())
				continue;
			CICircuit *pCircuit=(CICircuit *)*it_c;			
			CDisplayObj* pDisObj = pCircuit->GetDisplayObjByLayerID(layerId );
			if (pDisObj)
			{
				lCount+=1;
			}
		}
	}

	const std::list<CConnector *> & ConnectorList=pSystem->GetConnectorList();
	std::list<CConnector *>::const_iterator it_conn;
	for(it_conn=ConnectorList.begin(); it_conn!=ConnectorList.end(); ++it_conn)
	{
		CDisplayObj *pConnectorDisObj =(*(*it_conn)).GetDisplayObjByLayerID(layerId);
		if (pConnectorDisObj)
		{
			lCount+=1;
		}	
	}	

	const std::list<CCable *> & CableList=pSystem->GetCableList();
	std::list<CCable *>::const_iterator it_cable;
	for(it_cable=CableList.begin(); it_cable!=CableList.end(); ++it_cable)
	{
		const std::list<CSubCable *> & SubCableList=(*it_cable)->GetSubCableList();
		std::list<CSubCable *>::const_iterator it_sc;
		for(it_sc=SubCableList.begin(); it_sc!=SubCableList.end(); ++it_sc)
			lCount+=1;
	}

	std::list<CShape*> shapeList = pLayer->getShapeList();
	lCount+=shapeList.size();

	// 	const std::list<CSubSystem *> & SubSystemList=pSystem->GetSubSystemList();
	// 	std::list<CSubSystem *>::const_iterator it_ss;
	// 	for(it_ss=SubSystemList.begin(); it_ss!=SubSystemList.end(); ++it_ss)
	// 		CountDisplayObj(*it_ss, lCount);
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportTextAnnotationByLayer( CLayer * pLayer, IAcadModelSpace * m_pModelSpace ) 
{
	if (IsStopLayerExport())
		return false;
	std::list<CNoteObj*> lstNoteObj = pLayer->GetNoteList();
	for (std::list<CNoteObj*>::iterator it_NoteObj = lstNoteObj.begin();
		it_NoteObj!=lstNoteObj.end();it_NoteObj++)
	{
		if (IsStopLayerExport())
		{
			return false;
		}
		CNoteObj* pNoteObj = *it_NoteObj;
		if (pNoteObj->IsTextNote())
		{
			CTextNoteObj* pTextNoteObj = (CTextNoteObj*)pNoteObj;
			bool bRet = 	ExportTextAnnotation(m_pModelSpace,pTextNoteObj);
			if(!bRet)
				return false;
		}
	}

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSchematicConnectivtyByLayer( CLayer* pLayer, IAcadModelSpace * m_pModelSpace ) 
{
	std::list<CSchematicConnectivty*> lstSchConnectivties = pLayer->GetConnectivties();
	for (std::list<CSchematicConnectivty*>::iterator it_SchConnectivties = lstSchConnectivties.begin();
		it_SchConnectivties!=lstSchConnectivties.end();it_SchConnectivties++)
	{
		if (IsStopLayerExport())
		{
			return false;
		}
		CSchematicConnectivty* pSchConnectivty = *it_SchConnectivties;
		CSchematicWire* pSchWire = pSchConnectivty->GetWire();
		CSchematicWireDisObj* pSchWireDisObj = (CSchematicWireDisObj*)pSchWire->GetDisplayObjByLayerID(pLayer->GetId());
		ExportSchematicWire(m_pModelSpace,pSchWireDisObj);
	}

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSchematicBusByLayer( CLayer* pLayer, IAcadModelSpace * m_pModelSpace )
{
	std::list<CSchematicBus*> lstSchBus = pLayer->GetSchBusList();
	for (std::list<CSchematicBus*>::iterator it_SchBus = lstSchBus.begin();
		it_SchBus!=lstSchBus.end();it_SchBus++)
	{
		if (IsStopLayerExport())
		{
			return false;
		}
		CSchematicBus* pSchBus = *it_SchBus;
		CSchematicBusDisplayObj* pSchBusDisObj = (CSchematicBusDisplayObj*)pSchBus->GetDisplayObjByLayerID(pLayer->GetId());
		bool bRet =		ExportSchematicBus(m_pModelSpace,pSchBusDisObj);
		if(!bRet)
			return false;
		std::list<CSchematicBusEntry*> lstSchBusEntry = pSchBus->GetSchBusEntryList();
		for (std::list<CSchematicBusEntry*>::iterator it_SchBusEntry =lstSchBusEntry.begin();
			it_SchBusEntry!=lstSchBusEntry.end();it_SchBusEntry++)
		{
			if (IsStopLayerExport())
			{
				return false;
			}
			CSchematicBusEntryDisplayObj* pSchBusEntryDisObj = (CSchematicBusEntryDisplayObj*)(*it_SchBusEntry)->GetDisplayObjByLayerID(pLayer->GetId());
			bool bRet =		ExportSchematicBusEntry(m_pModelSpace,pSchBusEntryDisObj);
			if(!bRet)
				return false;
		}
	}
}

//导出文本注释对象(单行、多行情况)

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportTextAnnotation( IAcadModelSpace *pModelSpace, CTextNoteObj *pTextNoteDisObj ) const
{
	if(!pModelSpace)
		return false;
	CString szContent = pTextNoteDisObj->GetText();
	double dblLeft,dblRight,dblTop,dblBottom;
	dblLeft = dblRight = dblTop = dblBottom = 0;
	pTextNoteDisObj->GetBox(dblLeft,dblBottom,dblRight,dblTop);
	double dblWidth,dblHeight;
	dblWidth = dblRight-dblLeft;
	dblHeight = dblTop - dblBottom;
	double dblPosX = pTextNoteDisObj->GetPosX();
	double dblPosY = pTextNoteDisObj->GetPosY();
	int bkTypte = pTextNoteDisObj->GetBkType();
	double dblTextSize = 0.75*pTextNoteDisObj->GetTextSize();
	if (bkTypte ==	BG_QUAD)
	{
		//画方框
		double titlePts[]={	dblPosX-dblWidth/2, dblPosY-dblTextSize, 0,
			dblPosX+dblWidth/2, dblPosY-dblTextSize, 0,
			dblPosX+dblWidth/2, dblPosY+dblTextSize, 0,
			dblPosX-dblWidth/2, dblPosY+dblTextSize, 0,
		};
		COleSafeArray  saTitlePts;
		saTitlePts.CreateOneDim(VT_R8, 12, titlePts);        
		VARIANT * pvTitlePt =  (LPVARIANT)saTitlePts;
		IAcadPolyline *pPolyline=NULL;
		m_pModelSpace->AddPolyline(*pvTitlePt, &pPolyline);
		pPolyline->put_Closed(VARIANT_TRUE);
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pTextNoteDisObj->GetColorR()*255), (long)(pTextNoteDisObj->GetColorG()*255), (long)(pTextNoteDisObj->GetColorB()*255));
			pPolyline->put_TrueColor(pColor);
			pColor->Release();
		}
	}

	//多行注释则导出为MText
	if (szContent.Find(_T("\n"))!=-1)
	{
		double insert_pts[]={dblLeft, dblTop, 0};

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		IAcadMText* pMText = NULL;
		m_pModelSpace->AddMText(*pvInsertPts,dblWidth*1.2,bstr_t(szContent),&pMText);
		if(pMText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pTextNoteDisObj->GetTextColorR()*255), (long)(pTextNoteDisObj->GetTextColorG()*255), (long)(pTextNoteDisObj->GetTextColorB()*255));
				pMText->put_TrueColor(pColor);
				pColor->Release();
			}
			pMText->put_Height(dblTextSize);
			pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointTopLeft);

			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pTextNoteDisObj->GetTextFont());
			if(!strTextStyle.IsEmpty())
				pMText->put_StyleName(_bstr_t(strTextStyle));
			pMText->Release();
		}

	}
	else//单行注释
	{
		double insert_pts[]={dblPosX/*+dblWidth/4*/, dblPosY, 0};

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		IAcadText *pText=NULL;
		m_pModelSpace->AddText(bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);
		if(pText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{

				pColor->SetRGB((long)(pTextNoteDisObj->GetTextColorR()*255), (long)(pTextNoteDisObj->GetTextColorG()*255), (long)(pTextNoteDisObj->GetTextColorB()*255));
				pText->put_TrueColor(pColor);
				pColor->Release();
			}

			if (true)
			{
				pText->put_Alignment(AutoCAD::acAlignmentMiddle);
				pText->put_TextAlignmentPoint(*pvInsertPts);
			}
			else
			{
				pText->put_Alignment(AutoCAD::acAlignmentMiddle);
				pText->put_TextAlignmentPoint(*pvInsertPts);
				pText->put_Rotation(PI*0.5);
			}

			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pTextNoteDisObj->GetTextFont());
			if(!strTextStyle.IsEmpty())
				pText->put_StyleName(_bstr_t(strTextStyle));

			pText->Release();
		}
	}
	return true;
}

//导出总线信息-

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSchematicBus( IAcadModelSpace *pModelSpace, const CSchematicBusDisplayObj *pSchBusDisObj ) const
{
	if(!pModelSpace)
		return false;
	const std::list<std::pair<double, double> > & lstPt=pSchBusDisObj->GetPtList();
	if (lstPt.empty())
	{
		return true;
	}

	long lPtSize=lstPt.size();
	double * pts=new double[lPtSize*3];

	std::list<std::pair<double, double> >::const_iterator iter=lstPt.begin();

	//pts[0]=iter->first;
	//pts[1]=iter->second;
	//pts[2]=0;

	for(int i=0; iter!=lstPt.end(); ++iter,i++)
	{
		pts[3*i]=iter->first;
		pts[3*i+1]=iter->second;
		pts[3*i+2]=0;
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, lPtSize*3, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_FALSE);

	if(pSchBusDisObj->GetLineWidth()>1.0001)
		pPolyline->put_ConstantWidth(pSchBusDisObj->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pSchBusDisObj->GetColorR()*255), (long)(pSchBusDisObj->GetColorG()*255), (long)(pSchBusDisObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	eLinePattern lp=pSchBusDisObj->GetLinePattern();
	if(lp==DASH_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDEN")))
			pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
		//IAcadLineType *pLineType=NULL;
		//pLineTypes->Add(_bstr_t(""), &pLineType);

		//pLineType->get_Description()
		pPolyline->put_Linetype(_bstr_t("HIDDEN"));
		//pPolyline->put_LinetypeScale(0.1);
	}
	else if(lp==DOTTED_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DOT")))
			pLineTypes->Load(_bstr_t("DOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DOT"));
	}
	else if(lp==DASH_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DASHDOT")))
			pLineTypes->Load(_bstr_t("DASHDOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DASHDOT"));
	}
	else if(lp==DASH_DOUBLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DIVIDE")))
			pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DIVIDE"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("ACAD_ISO14W100")))
			pLineTypes->Load(_bstr_t("ACAD_ISO14W100"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("ACAD_ISO14W100"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDENX2")))
			pLineTypes->Load(_bstr_t("HIDDENX2"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("HIDDENX2"));
	}
	else if(lp==CENTER_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("CENTER")))
			pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("CENTER"));
	}
	else if(lp==PHANTOM_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("PHANTOM")))
			pLineTypes->Load(_bstr_t("PHANTOM"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("PHANTOM"));
	}

	pPolyline->Release();

	delete []pts;
	return true;
}

//导出总线入口

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSchematicBusEntry( IAcadModelSpace *pModelSpace, CSchematicBusEntryDisplayObj *pSchBusEntryDisObj ) const
{
	if(!pModelSpace)
		return false;
	HPoint startPoint,endPoint;
	pSchBusEntryDisObj->GetStartAndEndPoint(startPoint,endPoint);

	double * pts=new double[6];
	pts[0]=startPoint.x;
	pts[1]=startPoint.y;
	pts[2]=0;
	pts[3]=endPoint.x;
	pts[4]=endPoint.y;
	pts[5]=endPoint.z;

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 6, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	if(!pPolyline)
		return false;
	pPolyline->put_Closed(VARIANT_FALSE);

	if(pSchBusEntryDisObj->GetLineWidth()>1.0001)
		pPolyline->put_ConstantWidth(pSchBusEntryDisObj->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pSchBusEntryDisObj->GetColorR()*255), (long)(pSchBusEntryDisObj->GetColorG()*255), (long)(pSchBusEntryDisObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	eLinePattern lp=pSchBusEntryDisObj->GetLinePattern();
	if(lp==DASH_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDEN")))
			pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
		//IAcadLineType *pLineType=NULL;
		//pLineTypes->Add(_bstr_t(""), &pLineType);

		//pLineType->get_Description()
		pPolyline->put_Linetype(_bstr_t("HIDDEN"));
		//pPolyline->put_LinetypeScale(0.1);
	}
	else if(lp==DOTTED_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DOT")))
			pLineTypes->Load(_bstr_t("DOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DOT"));
	}
	else if(lp==DASH_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DASHDOT")))
			pLineTypes->Load(_bstr_t("DASHDOT"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DASHDOT"));
	}
	else if(lp==DASH_DOUBLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("DIVIDE")))
			pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("DIVIDE"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("ACAD_ISO14W100")))
			pLineTypes->Load(_bstr_t("ACAD_ISO14W100"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("ACAD_ISO14W100"));
	}
	else if(lp==DASH_TRIPLE_DOT_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("HIDDENX2")))
			pLineTypes->Load(_bstr_t("HIDDENX2"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("HIDDENX2"));
	}
	else if(lp==CENTER_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("CENTER")))
			pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("CENTER"));
	}
	else if(lp==PHANTOM_LINE)
	{
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if(!pDatabase)
			return false;
		IAcadLineTypes *pLineTypes=NULL;
		pDatabase->get_Linetypes(&pLineTypes);

		if(!ExistLineType(pLineTypes, _T("PHANTOM")))
			pLineTypes->Load(_bstr_t("PHANTOM"), _bstr_t("acadiso.lin"));
		pPolyline->put_Linetype(_bstr_t("PHANTOM"));
	}

	pPolyline->Release();

	delete []pts;
	return true;
}

//导出示意连线

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSchematicWire( IAcadModelSpace *pModelSpace, CSchematicWireDisObj *pSchWireDisObj ) const
{
	if (pSchWireDisObj && pSchWireDisObj->IsShowThis())
	{
		return ExportWire(m_pModelSpace,pSchWireDisObj);
	}
}

//导出连接线

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSubline( IAcadModelSpace *pModelSpace,CSublineDisplayObj *pSublineDisObj ) const
{
	if (!pSublineDisObj->IsShowThis())
	{
		return true;
	}
	std::list<std::pair<double, double>>  ptList = pSublineDisObj->GetMidPtList();
	int ptNum = ptList.size();
	double *pts = new double[3*ptNum];

	std::list<std::pair<double,double>>::iterator iter_Pos;
	int index =0;
	for( iter_Pos= ptList.begin();iter_Pos!=ptList.end();iter_Pos++)
	{
		pts[index++] = iter_Pos->first;
		pts[index++] = iter_Pos->second;
		pts[index++] = 0;
	}

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 3*ptNum, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;
	IAcadPolyline *pPolyLine = NULL;
	if(!pModelSpace)
		return false;
	m_pModelSpace->AddPolyline(*pvPts,&pPolyLine);
	pPolyLine->put_Closed(VARIANT_FALSE);
	if(!pPolyLine)
		return false;
	pPolyLine->put_LinetypeScale(1);

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pSublineDisObj->GetColorR()*255), (long)(pSublineDisObj->GetColorG()*255), (long)(pSublineDisObj->GetColorB()*255));
		pPolyLine->put_TrueColor(pColor);
		pColor->Release();
	}

	IAcadDatabase *pDatabase=NULL;
	m_pModelSpace->get_Database(&pDatabase);
	if(!pDatabase)
		return false;
	IAcadLineTypes *pLineTypes=NULL;
	pDatabase->get_Linetypes(&pLineTypes);

	eLinePattern linType = pSublineDisObj->GetLinePattern();
	switch(linType)
	{
	case DASH_LINE:

		if(!ExistLineType(pLineTypes, _T("HIDDEN")))
			pLineTypes->Load(_bstr_t("HIDDEN"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("HIDDEN"));

		break;

	case DOTTED_LINE:

		if(!ExistLineType(pLineTypes, _T("DOT")))
			pLineTypes->Load(_bstr_t("DOT"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("DOT"));

		break;

	case DASH_DOT_LINE:

		if(!ExistLineType(pLineTypes, _T("DASHDOT")))
			pLineTypes->Load(_bstr_t("DASHDOT"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("DASHDOT"));

		break;

	case DASH_DOUBLE_DOT_LINE:

		if(!ExistLineType(pLineTypes, _T("DIVIDE")))
			pLineTypes->Load(_bstr_t("DIVIDE"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("DIVIDE"));

		break;

	case DASH_TRIPLE_DOT_LINE:

		if(!ExistLineType(pLineTypes, _T("ACAD_ISO14W100")))
			pLineTypes->Load(_bstr_t("ACAD_ISO14W100"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("ACAD_ISO14W100"));

		break;

	case LONG_DASH_LINE:

		if(!ExistLineType(pLineTypes, _T("HIDDENX2")))
			pLineTypes->Load(_bstr_t("HIDDENX2"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("HIDDENX2"));

		break;

	case CENTER_LINE:

		if(!ExistLineType(pLineTypes, _T("CENTER")))
			pLineTypes->Load(_bstr_t("CENTER"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("CENTER"));

		break;

	case PHANTOM_LINE:

		if(!ExistLineType(pLineTypes, _T("PHANTOM")))
			pLineTypes->Load(_bstr_t("PHANTOM"), _bstr_t("acadiso.lin"));
		pPolyLine->put_Linetype(_bstr_t("PHANTOM"));

		break;

	default:
		break;
	}


	delete []pts;

	pDatabase->Release();
	pLineTypes->Release();
	pPolyLine->Release();

	if ( !pSublineDisObj->IsShowTracker())
	{
		return true;
	}

	list<CTrackerDisplayObj*> lstTrackers = pSublineDisObj->GetTrackerList();
	list<CTrackerDisplayObj*>::iterator iter = lstTrackers.begin();
	for ( ; iter!= lstTrackers.end();iter++)
	{
		CTrackerDisplayObj* pTraker = *iter;
		double dPosX = pTraker->GetPosX();
		double dPosY = pTraker->GetPosY();
		COleSafeArray   safeOleArr;
		double   dValues[3]={dPosX,dPosY, 0};       
		safeOleArr.CreateOneDim(VT_R8,3,dValues);        
		VARIANT   *   pNewPointVariant   =   (LPVARIANT)safeOleArr;     
		IAcadCircle *pCircle=NULL;
		m_pModelSpace->AddCircle(*pNewPointVariant, pTraker->GetWidth(), &pCircle);

		pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pTraker->GetColorR()*255), (long)(pTraker->GetColorG()*255), (long)(pTraker->GetColorB()*255));
			pCircle->put_TrueColor(pColor);
			pColor->Release();
		}

		IAcadHatch *pHatch=NULL;
		m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
		if(pHatch)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pTraker->GetColorR()*255), (long)(pTraker->GetColorG()*255), (long)(pTraker->GetColorB()*255));
				pHatch->put_TrueColor(pColor);
				pColor->Release();
			}

			COleSafeArray saLoop;
			saLoop.CreateOneDim(VT_DISPATCH, 1, &pCircle);
			VARIANT * pvLoop=(LPVARIANT)saLoop;
			pHatch->AppendOuterLoop(*pvLoop);
			pHatch->Release();
		}
	}
	
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::DoLayerExport(IAcadModelSpace *pModelSpace, CSystem *pSystem)
{	
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if(m_ListLayer.empty())
	{
		return true;
	}
	//////////////////////////////////////////////////////////////////////////////////
	m_pNumInfo->pStatic->SetWindowTextW(_T("正在准备导出数据到AutoCAD..."));
	long lCount=0,temp=0;
	//CountDisplayObj(pSystem, lCount);	
	std::list<CLayer *>::const_iterator iter;	
	for(iter=m_ListLayer.begin(); iter!=m_ListLayer.end(); ++iter)
	{		
		if (pSystem->GetSystemType() != ELECTRIC_SYSTEM)
		{
			if ((*iter)->GetLayerLevelType() == TOP_LEVEL_LAYER)
			{
				continue;
			}
		}
		CountLayerDisplayObj(pSystem,*iter,temp);	
		lCount+=temp;
		temp=0;
	}
	long lStepCount=lCount;
	m_pNumInfo->m_Progress->SetRange32(0, lStepCount);
	m_pNumInfo->m_Progress->SetStep(1);
	/////////////////////////////////////////////////////////////////////////
	std::list<CLayer *>  LayerList=m_ListLayer;
	//	LayerList.reverse();
	std::list<CLayer *>::const_iterator it_layer;
	m_dblViewOffset=0;
	for(it_layer=LayerList.begin(); it_layer!=LayerList.end(); ++it_layer)
	{		
		if (pSystem->GetSystemType() != ELECTRIC_SYSTEM)
		{
			if ((*it_layer)->GetLayerLevelType() == TOP_LEVEL_LAYER)
			{
				continue;
			}
		}
		IAcadDatabase *pDatabase=NULL;
		m_pModelSpace->get_Database(&pDatabase);
		if (!pDatabase)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		IAcadLayers *pLayers=NULL;
		pDatabase->get_Layers(&pLayers);
		pDatabase->Release();
		if (!pLayers)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		IAcadLayer *pLayer=NULL;
		pLayers->Add(_bstr_t((*it_layer)->GetName()), &pLayer);
		pLayer->put_LayerOn(VARIANT_TRUE);
		if (!pLayer)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		IAcadDocument *pDoc=NULL;
		m_pAcadApp->get_ActiveDocument(&pDoc);
		if (!pDoc)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		IAcadLayer *pActiveLayer=NULL;
		pDoc->get_ActiveLayer(&pActiveLayer);
		if (!pActiveLayer)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}

		pDoc->Release();
		pDoc->put_ActiveLayer(pLayer);
		pLayer->Release();

		if(pActiveLayer)
		{
			pActiveLayer->put_LayerOn(VARIANT_FALSE);
			pActiveLayer->Release();
		}

		IAcadDatabase *pDb=NULL;
		m_pModelSpace->get_Database(&pDb);
		if (!pDb)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		IAcadBlocks *pBlocks=NULL;
		pDb->get_Blocks(&pBlocks);
		pDb->Release();
		if (!pBlocks)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		CExportProgressDlg *pProgressDlg=NULL;
		bool bRet =		ExportCircuitAsBlockDef(pBlocks, pSystem, (*it_layer)->GetId(), pProgressDlg);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}

		pBlocks->Release();

		bRet =		DoExportByLayer(m_pModelSpace, pSystem, (*it_layer)->GetId(), pProgressDlg);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出注释
		bRet =		ExportTextAnnotationByLayer(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出图形注释
		bRet =		ExportShapeDisByLayer(*it_layer,m_pModelSpace,pProgressDlg);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出连接关系
		bRet =		ExportSchematicConnectivtyByLayer(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出总线信息
		bRet =		ExportSchematicBusByLayer(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出接地桩
		bRet =		ExportGroundUnit(*it_layer, m_pModelSpace);	
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		bRet =		ExportGroundUnit_RegionManager(*it_layer, m_pModelSpace);	
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出接地符号
		bRet =		ExportGroundPatterns(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
		//输出图纸模板 xiongyb@06907
		bRet =		ExportPageTemplate(*it_layer, m_pModelSpace);
		if (!bRet)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出数据失败！（导出过程中请勿操作AutoCad）"));
			return false;
		}
	}	
	m_ListLayer.clear();	
	if (m_pNumInfo)
	{
		if(m_pNumInfo->m_bStop)
		{
			m_pNumInfo->pStatic->SetWindowTextW(_T("已取消导出"));
			m_pNumInfo->pStopBtn->EnableWindow(FALSE);
			m_pNumInfo->pStartBtn->EnableWindow(TRUE);	
			m_pNumInfo->pListLayer->clear();
			m_pNumInfo->m_Progress->SetPos(0);			
		}	 
		else
		{	
			m_pNumInfo->pStatic->SetWindowTextW(_T("导出完成"));	    

			m_pNumInfo->m_Progress->/*SetPos(m_lProgressPos)*/SetPos(lStepCount);
			CWnd *pWnd;
			pWnd=CWnd::FromHandle( m_pNumInfo->hwnd);		 
			pWnd->SendMessage(WM_CLOSE);
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportShapeDisByLayer( CLayer* pLayer,IAcadModelSpace * m_pModelSpace,CExportProgressDlg *pProgressDlg )
{
	if (IsStopLayerExport())
		return false;
	std::list<CShape*> shapeList = pLayer->getShapeList();
	for (std::list<CShape*>::iterator it_ShapeObj = shapeList.begin();
		it_ShapeObj!=shapeList.end();it_ShapeObj++)
	{
		if (IsStopLayerExport())
		{
			return false;
		}
		CShape* pShape = *it_ShapeObj;
		CShapeDisplayObj* pShapeDis = dynamic_cast<CShapeDisplayObj*>(pShape->GetDisplayObjByLayerID(pLayer->GetId()));
		eShapeStyle type = pShape->getShapeStyle();
		switch (type)
		{
		case SHAPE_ELLIPSE:
			{
				CString szTxt=_T("正在导出椭圆注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CEllipsDisplayObj* pEllipsDis = dynamic_cast<CEllipsDisplayObj*>(pShapeDis);
				bool bRet =		ExportEllipsDis(m_pModelSpace,pEllipsDis);
				// 				if (!bRet)
				// 					return false;
				break;
			}			
		case SHAPE_IMAGE:
			{
				CString szTxt=_T("正在导出图片注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CImageDisplayObj* pImageDis = dynamic_cast<CImageDisplayObj*>(pShapeDis);
				bool bRet =		ExportImageDis(m_pModelSpace,pImageDis);
				if (!bRet)
					return false;
				break;
			}
		case SHAPE_LINE:
			{
				CString szTxt=_T("正在导出直线注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CLineDisplayObj* pLineDis = dynamic_cast<CLineDisplayObj*>(pShapeDis);
				bool bRet =		ExportShapeLineDisInLayer(m_pModelSpace,pLineDis);
				if (!bRet)
					return false;
				break;
			}
		case SHAPE_POLYGON:
			{
				CString szTxt=_T("正在导出多边形注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CPolygonDisplayObj* pPolyDis = dynamic_cast<CPolygonDisplayObj*>(pShapeDis);
				bool bRet =		ExportPolygonDis(m_pModelSpace,pPolyDis);
				if (!bRet)
					return false;
				break;
			}
		case SHAPE_RECTANGLE:
			{
				CString szTxt=_T("正在导出矩形注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CRectangleDisplayObj* pRectDis = dynamic_cast<CRectangleDisplayObj*>(pShapeDis);
				bool bRet =		ExportRectangleDis(m_pModelSpace,pRectDis);
				if (!bRet)
					return false;
				break;
			}
		case SHAPE_ROUND_RECTANGLE:
			{
				CString szTxt=_T("正在导出圆角矩形注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CRoundRectangleDisplayObj* pRoundRectDis = dynamic_cast<CRoundRectangleDisplayObj*>(pShapeDis);
				bool bRet =		ExportRoundRectangleDis(m_pModelSpace,pRoundRectDis);
				if (!bRet)
					return false;
				break;
			}
		case SHAPE_CURVE:
			{
				CString szTxt=_T("正在导出曲线注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	
				CCurveDisplayObj* pCurveDis = dynamic_cast<CCurveDisplayObj*>(pShapeDis);
				bool bRet =		ExportCurveDis(m_pModelSpace,pCurveDis);
				if (!bRet)
					return false;
				break;
			}
		case SHAPE_WORD:
			{
				CString szTxt=_T("正在导出文本注释");
				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	
				CWordDisplayObj* pWordDis = dynamic_cast<CWordDisplayObj*>(pShapeDis);
				bool bRet =		ExportWordDis(m_pModelSpace,pWordDis);
				if (!bRet)
					return false;
				break;
			}
		default:
			break;
		}

	}
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportShapeDisObj(CLayer* pLayer,IAcadModelSpace * m_pModelSpace,CExportProgressDlg *pProgressDlg,long lLayerId, std::list<CShape* > shapeList)
{
	for (std::list<CShape*>::iterator it_ShapeObj = shapeList.begin();	it_ShapeObj!=shapeList.end();it_ShapeObj++)
	{
		if (IsStopLayerExport())
		{
			return false;
		}
		CShape* pShape = *it_ShapeObj;
		CShapeDisplayObj *pShapeDis = (CShapeDisplayObj *)pShape->GetDisplayObjByLayerID(lLayerId);
		if (!pShapeDis)
		{
			return true;
		}
		eShapeStyle type = pShape->getShapeStyle();
		switch (type)
		{
		case SHAPE_ELLIPSE:
			{
				// 				CString szTxt=_T("正在导出椭圆注释");
				// 				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CEllipsDisplayObj* pEllipsDis = dynamic_cast<CEllipsDisplayObj*>(pShapeDis);
				ExportEllipsDis(m_pModelSpace,pEllipsDis);
				break;
			}			
		case SHAPE_IMAGE:
			{
				// 				CString szTxt=_T("正在导出图片注释");
				// 				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CImageDisplayObj* pImageDis = dynamic_cast<CImageDisplayObj*>(pShapeDis);
				ExportImageDis(m_pModelSpace,pImageDis);
				break;
			}
		case SHAPE_LINE:
			{
				// 				CString szTxt=_T("正在导出直线注释");
				// 				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CLineDisplayObj* pLineDis = dynamic_cast<CLineDisplayObj*>(pShapeDis);
				ExportLineDis(m_pModelSpace,pLineDis);
				break;
			}
		case SHAPE_POLYGON:
			{
				// 				CString szTxt=_T("正在导出多边形注释");
				// 				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CPolygonDisplayObj* pPolyDis = dynamic_cast<CPolygonDisplayObj*>(pShapeDis);
				ExportPolygonDis(m_pModelSpace,pPolyDis);
				break;
			}
		case SHAPE_RECTANGLE:
			{
				// 				CString szTxt=_T("正在导出矩形注释");
				// 				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CRectangleDisplayObj* pRectDis = dynamic_cast<CRectangleDisplayObj*>(pShapeDis);
				ExportRectangleDis(m_pModelSpace,pRectDis);
				break;
			}
		case SHAPE_ROUND_RECTANGLE:
			{
				// 				CString szTxt=_T("正在导出圆角矩形注释");
				// 				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	

				CRoundRectangleDisplayObj* pRoundRectDis = dynamic_cast<CRoundRectangleDisplayObj*>(pShapeDis);
				ExportRoundRectangleDis(m_pModelSpace,pRoundRectDis);
				break;
			}
		case SHAPE_CURVE:
			{
				// 				CString szTxt=_T("正在导出曲线注释");
				// 				ShowInterfaceInfo(m_pNumInfo,szTxt,pProgressDlg);	
				CCurveDisplayObj* pCurveDis = dynamic_cast<CCurveDisplayObj*>(pShapeDis);
				ExportCurveDis(m_pModelSpace,pCurveDis);
				break;
			}
		case SHAPE_WORD:
			{
				CWordDisplayObj* pWordDis = dynamic_cast<CWordDisplayObj*>(pShapeDis);
				ExportGroundPatternWordDis(m_pModelSpace, pWordDis);
				break;
			}
		default:
			break;
		}

	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportShapeLineDisInLayer(IAcadModelSpace *pModelSpace,CLineDisplayObj *pLineDis) const
{
	if(!pModelSpace)
		return false;
	CLineObj* lineObj = (CLineObj*)(pLineDis->GetEntityObj());

	double x0 = ( pLineDis->getStartPos().x + dbTranslate_x ) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y0 = (pLineDis->getStartPos().y + dbTranslate_y) * iV * dbScale_y + dbTranslateBack_y;
	double x1 = (pLineDis->getEndPos().x + dbTranslate_x) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y1 = (pLineDis->getEndPos().y + dbTranslate_y) * iV * dbScale_y + dbTranslateBack_y;			
	double ptsStart[3]={x0,y0,0.0};
	double ptsEnd[3] = {x1,y1,0.0};

	double pts[]={	x0, y0, 0,
		x1, y1, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 6, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	//		pPolyline->put_ConstantWidth(lineObj->GetWidth());
	if (!pPolyline)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pLineDis->GetColorR()*255), (long)(pLineDis->GetColorG()*255), (long)(pLineDis->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportLineDis( IAcadModelSpace *pModelSpace,CLineDisplayObj *pLineDis ) const
{
	if(!pModelSpace)
		return false;
	CLineObj* lineObj = (CLineObj*)(pLineDis->GetEntityObj());

	double x0 = ( lineObj->GetStartPosX() + dbTranslate_x ) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y0 = (lineObj->GetStartPosY() + dbTranslate_y) * iV * dbScale_y + dbTranslateBack_y;
	double x1 = (lineObj->GetEndPosX() + dbTranslate_x) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y1 = (lineObj->GetEndPosY() + dbTranslate_y) * iV * dbScale_y + dbTranslateBack_y;			
	double ptsStart[3]={x0,y0,0.0};
	double ptsEnd[3] = {x1,y1,0.0};

	double pts[]={	x0, y0, 0,
		x1, y1, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 6, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	//		pPolyline->put_ConstantWidth(lineObj->GetWidth());
	if (!pPolyline)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(lineObj->GetColorR()*255), (long)(lineObj->GetColorG()*255), (long)(lineObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	//		pPolyline->Release();


	// 		COleSafeArray   saPtsStart,saPtsEnd;
	// 		saPtsStart.CreateOneDim(VT_R8, 3, ptsStart); 
	// 		saPtsEnd.CreateOneDim(VT_R8, 3, ptsEnd); 
	// 		VARIANT * pvPtsStart =  (LPVARIANT)saPtsStart;
	// 		VARIANT * pvPtsEnd =  (LPVARIANT)saPtsEnd;
	// 		IAcadLine *pLine=NULL;
	// 		m_pModelSpace->AddLine(*pvPtsStart, *pvPtsEnd,&pLine);
	// 		
	// 		IAcadAcCmColor *pColor=GetColor();
	// 		if(pColor)
	// 		{
	// 			pColor->SetRGB((long)(pLineDis->GetColorR()*255), (long)(pLineDis->GetColorG()*255), (long)(pLineDis->GetColorB()*255));
	// 			pLine->put_TrueColor(pColor);
	// 			pColor->Release();
	// 		}
	// 
	// 		IAcadHatch *pHatch=NULL;
	// 		m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	// 		if(pHatch)
	// 		{
	// 			IAcadAcCmColor *pColor=GetColor();
	// 			if(pColor)
	// 			{
	// 				pColor->SetRGB((long)(pLineDis->GetFillColorR()*255), (long)(pLineDis->GetFillColorG()*255), (long)(pLineDis->GetFillColorB()*255));
	// 				pHatch->put_TrueColor(pColor);
	// 				pColor->Release();
	// 			}
	// 			COleSafeArray saLoop;				
	// 			saLoop.CreateOneDim(VT_DISPATCH, 1, &pLine);
	// 			VARIANT * pvLoop=(LPVARIANT)saLoop;
	// 			pHatch->AppendOuterLoop(*pvLoop);
	// 			pHatch->Release();			
	// 		}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportRectangleDis( IAcadModelSpace *pModelSpace,CRectangleDisplayObj *pRectDis ) const
{
	if(!pModelSpace)
		return false;
	CRectangleObj* recObj = (CRectangleObj*)pRectDis->GetEntityObj();
	COleSafeArray   saPts;			
	double x0 = (pRectDis->getStartPos().x + dbTranslate_x) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y0 = (pRectDis->getStartPos().y + dbTranslate_y) * dbScale_y * iV +dbTranslateBack_y;
	double x1 = (pRectDis->getEndPos().x + dbTranslate_x) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y1 = (pRectDis->getEndPos().y + dbTranslate_y) * dbScale_y  * iV + dbTranslateBack_y;			
	double pts[]={x0,y0,0.0,
		x1,y0,0.0,
		x1,y1,0.0,
		x0,y1,0.0};
	saPts.CreateOneDim(VT_R8, 12, pts); 
	VARIANT * pvPts =  (LPVARIANT)saPts;    
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_TRUE);
	if (!pPolyline)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(recObj->GetColorR()*255), (long)(recObj->GetColorG()*255), (long)(recObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pRectDis->GetFillColorR()*255), (long)(pRectDis->GetFillColorG()*255), (long)(pRectDis->GetFillColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}

		COleSafeArray saLoop;				
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
		VARIANT * pvLoop=(LPVARIANT)saLoop;

		pHatch->AppendOuterLoop(*pvLoop);

		pHatch->Release();
	}				
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportRoundRectangleDis( IAcadModelSpace *pModelSpace,CRoundRectangleDisplayObj *pRoundRectDis ) const
{
	if(!pModelSpace)
		return false;
	double x0 = (pRoundRectDis->getStartPos().x + dbTranslate_x)*dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y0 = (pRoundRectDis->getStartPos().y + dbTranslate_y)*dbScale_y* iV + dbTranslateBack_y ;
	double x1 = (pRoundRectDis->getEndPos().x + dbTranslate_x)*dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y1 = (pRoundRectDis->getEndPos().y + dbTranslate_y)*dbScale_y *iV + dbTranslateBack_y ;
	//求左下角和右上角坐标
	float left = min(x0, x1);
	float down = min(y0, y1);
	float right = max(x0, x1);
	float up = max(y0, y1);

	//求半径
	float width = right-left;
	float height = up-down;
	float radius = 0.15 * min(width,height);

	//求4个圆角的离散点
	int nPoints = 10; //单个圆弧的离散点数=段数+1
	int pt_counts = 4*nPoints;
	HPoint * pts = new HPoint[pt_counts];

	//右上角圆弧:0-90度
	HPoint center1(right-radius, up-radius);
	int nPtIndex = 0;
	int angle = 0;
	for (int i=0; i<nPoints; i++, nPtIndex++)
	{
		double radian = PI*angle/180.0;

		HPoint pt_temp = center1;
		pt_temp.x += radius*cos(radian);
		pt_temp.y += radius*sin(radian); 
		pts[nPtIndex] = pt_temp;

		angle += 10;
	}

	//左上角圆弧：90-180度
	HPoint center2(left+radius, up-radius);
	angle -= 10;
	for (int i=0; i<nPoints; i++,nPtIndex++)
	{
		double radian = PI*angle/180.0;

		HPoint pt_temp = center2;
		pt_temp.x += radius*cos(radian);
		pt_temp.y += radius*sin(radian); 
		pts[nPtIndex] = pt_temp;

		angle += 10;
	}

	//左下角圆弧：180-270度
	HPoint center3(left+radius, down+radius);
	angle -= 10;
	for (int i=0; i<nPoints; i++,nPtIndex++)
	{
		double radian = PI*angle/180.0;

		HPoint pt_temp = center3;
		pt_temp.x += radius*cos(radian);
		pt_temp.y += radius*sin(radian); 
		pts[nPtIndex] = pt_temp;

		angle += 10;
	}

	//右下角圆弧：270-360度
	HPoint center4(right-radius, down+radius);
	angle -= 10;
	for (int i=0; i<nPoints; i++,nPtIndex++)
	{
		double radian = PI*angle/180.0;

		HPoint pt_temp = center4;
		pt_temp.x += radius*cos(radian);
		pt_temp.y += radius*sin(radian); 
		pts[nPtIndex] = pt_temp;

		angle += 10;
	}
	// 	HPoint pt_start = center1;
	// 	pt_start.x += radius*cos(0.0);
	// 	pt_start.y += radius*sin(0.0);
	// 	pts[nPtIndex] = pt_start;



	const int m = 3*pt_counts;
	double *dpts = new double[m];
	for (int i = 0;i < pt_counts;i++)
	{
		dpts[3*i + 0] = pts[i].x + m_dblViewOffset;
		dpts[3*i + 1] = pts[i].y;
		dpts[3*i + 2] = 0.0;
	}		
	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, m, dpts); 
	VARIANT * pvPts =  (LPVARIANT)saPts;
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_TRUE);
	if (!pPolyline)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pRoundRectDis->GetColorR()*255), (long)(pRoundRectDis->GetColorG()*255), (long)(pRoundRectDis->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch && ((CCircuitRoundRect*)(pRoundRectDis->GetEntityObj()))->IsFill())
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pRoundRectDis->GetFillColorR()*255), (long)(pRoundRectDis->GetFillColorG()*255), (long)(pRoundRectDis->GetFillColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}
		COleSafeArray saLoop;				
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
		VARIANT * pvLoop=(LPVARIANT)saLoop;
		pHatch->AppendOuterLoop(*pvLoop);
		pHatch->Release();			
	}
	delete []dpts;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportEllipsDis( IAcadModelSpace *pModelSpace,CEllipsDisplayObj* pEllipsDis ) const
{
	if(!pModelSpace)
		return false;
	double x0 = pEllipsDis->getStartPos().x + dbTranslate_x;
	double y0 = (pEllipsDis->getStartPos().y + dbTranslate_y) * iV;
	double x1 = pEllipsDis->getEndPos().x + dbTranslate_x;
	double y1 = (pEllipsDis->getEndPos().y + dbTranslate_y) * iV;	
	x0 =  x0 * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	y0 = y0 * dbScale_y + dbTranslateBack_y;
	x1 = x1 * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	y1 = y1 * dbScale_y + dbTranslateBack_y;
	float left = min(x0, x1);
	float down = min(y0, y1);
	float right = max(x0, x1);
	float up = max(y0, y1);

	float width = right-left;
	float height = up-down;

	//double ratio;
	//double ptsMajor[3];
	//if (width > height)
	//{
	//	ratio =height/width;
	//	ptsMajor[0] = right;
	//	ptsMajor[1] = 0.5*(y0+y1);
	//	ptsMajor[2] = 0.0;
	//}
	//else
	//{
	//	ratio = width / height;
	//	ptsMajor[0] = 0.5*(x0+x1);
	//	ptsMajor[1] = up;
	//	ptsMajor[2] = 0.0;
	//}		
	//double ptsCenter[3]={0.5*(x0+x1),0.5*(y0+y1),0.0};

	//COleSafeArray   saPtsCenter,saPtsMajor;
	//saPtsCenter.CreateOneDim(VT_R8, 3, ptsCenter); 
	//saPtsMajor.CreateOneDim(VT_R8,3,ptsMajor);
	//VARIANT * pvPtsCenter =  (LPVARIANT)saPtsCenter;
	//VARIANT* pvPtsMajor = (LPVARIANT)saPtsMajor;
	//IAcadEllipse *pEllips=NULL;
	//m_pModelSpace->AddEllipse(*pvPtsCenter, *pvPtsMajor,ratio,&pEllips);

	long pts_size=3;
	double pts[]={ min(x0, x1)+width/2 , min(y0, y1)+height/2, 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	pts[0]=width/2;
	pts[1]=0;

	COleSafeArray major;
	major.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvMajor =  (LPVARIANT)major;

	double dblRatio=height/width;

	IAcadEllipse *pEllips=NULL;
	pModelSpace->AddEllipse(*pvPts, *pvMajor, dblRatio, &pEllips);

	if (!pEllips)
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pEllipsDis->GetColorR()*255), (long)(pEllipsDis->GetColorG()*255), (long)(pEllipsDis->GetColorB()*255));
		pEllips->put_TrueColor(pColor);
		pColor->Release();
	}

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pEllipsDis->GetFillColorR()*255), (long)(pEllipsDis->GetFillColorG()*255), (long)(pEllipsDis->GetFillColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}
		COleSafeArray saLoop;				
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pEllips);
		VARIANT * pvLoop=(LPVARIANT)saLoop;
		pHatch->AppendOuterLoop(*pvLoop);
		pHatch->Release();			
	}					
	return true;	
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportPolygonDis( IAcadModelSpace *pModelSpace,CPolygonDisplayObj* pPolygonDis ) const
{	
	if(!pModelSpace)
		return false;
	CPolygonObj* polObj = (CPolygonObj*)pPolygonDis->GetEntityObj();
	vector<HPoint> points = pPolygonDis->GetAllPoints();
	int n = points.size();
	const int m = 3*n;
	if (m > 0)
	{
		double *pts = new double[m];
		for (int i = 0;i < n;i++)
		{
			pts[3*i + 0] = (points.at(i).x + dbTranslate_x)*dbScale_x + dbTranslateBack_x + m_dblViewOffset;
			pts[3*i + 1] = (points.at(i).y + dbTranslate_y)*dbScale_y * iV + dbTranslateBack_y;
			pts[3*i + 2] = 0.0;
		}
		COleSafeArray   saPts;
		saPts.CreateOneDim(VT_R8, m, pts); 
		VARIANT * pvPts =  (LPVARIANT)saPts;
		IAcadPolyline *pPolyline=NULL;
		m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
		pPolyline->put_Closed(VARIANT_TRUE);
		if (!pPolyline)
			return false;
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(polObj->GetColorR()*255), (long)(polObj->GetColorG()*255), (long)(polObj->GetColorB()*255));
			pPolyline->put_TrueColor(pColor);
			pColor->Release();
		}

		IAcadHatch *pHatch=NULL;
		m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
		if(pHatch)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pPolygonDis->GetFillColorR()*255), (long)(pPolygonDis->GetFillColorG()*255), (long)(pPolygonDis->GetFillColorB()*255));
				pHatch->put_TrueColor(pColor);
				pColor->Release();
			}
			COleSafeArray saLoop;				
			saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
			VARIANT * pvLoop=(LPVARIANT)saLoop;
			pHatch->AppendOuterLoop(*pvLoop);
			pHatch->Release();			
		}
		delete []pts;
	}		
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCurveDis(IAcadModelSpace *pModelSpace,CCurveDisplayObj* pCurveDis) const
{
	if(!pModelSpace)
		return false;
	CCurveObj* curveObj = (CCurveObj*)pCurveDis->GetEntityObj();
	double x0 = (curveObj->GetStartPosX() + dbTranslate_x) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y0 = (curveObj->GetStartPosY() + dbTranslate_y) * dbScale_y * iV + dbTranslateBack_y ;
	double x1 = (curveObj->GetFirPosX()  + dbTranslate_x) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y1 = (curveObj->GetFirPosY() + dbTranslate_y) * dbScale_y * iV + dbTranslateBack_y ;
	double x2 = (curveObj->GetSecPosX() + dbTranslate_x) * dbScale_x + dbTranslateBack_x + m_dblViewOffset;
	double y2 = (curveObj->GetSecPosY() + dbTranslate_y) * dbScale_y * iV + dbTranslateBack_y ;
	double x3 = (curveObj->GetEndPosX() + dbTranslate_x) * dbScale_x + dbTranslateBack_x  + m_dblViewOffset;
	double y3 = (curveObj->GetEndPosY() + dbTranslate_y) * dbScale_y * iV + dbTranslateBack_y ;			
	double ptsStart[3]={x0,y0,0.0};
	double ptsFir[3] = {x1,y1,0.0};
	double ptsSec[3] = {x2,y2,0.0};
	double ptsEnd[3] = {x3,y3,0.0};
	COleSafeArray   saPtsStart,saPtsFir,saPtsSec,saPtsEnd;
	saPtsStart.CreateOneDim(VT_R8, 3, ptsStart); 
	saPtsFir.CreateOneDim(VT_R8, 3, ptsFir); 
	saPtsSec.CreateOneDim(VT_R8, 3, ptsSec); 
	saPtsEnd.CreateOneDim(VT_R8, 3, ptsEnd); 
	VARIANT * pvPtsStart =  (LPVARIANT)saPtsStart;
	VARIANT * pvPtsFir =  (LPVARIANT)saPtsFir;
	VARIANT * pvPtsSec =  (LPVARIANT)saPtsSec;
	VARIANT * pvPtsEnd =  (LPVARIANT)saPtsEnd;
	IAcadLine *pLine0=NULL;
	IAcadLine *pLine1=NULL;
	IAcadLine *pLine2=NULL;
	m_pModelSpace->AddLine(*pvPtsStart, *pvPtsFir,&pLine0);
	m_pModelSpace->AddLine(*pvPtsFir, *pvPtsSec,&pLine1);
	m_pModelSpace->AddLine(*pvPtsSec, *pvPtsEnd,&pLine2);
	if ( !pLine0 ||!pLine1 ||!pLine2  )
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(curveObj->GetColorR()*255), (long)(curveObj->GetColorG()*255), (long)(curveObj->GetColorB()*255));
		pLine0->put_TrueColor(pColor);
		pLine1->put_TrueColor(pColor);
		pLine2->put_TrueColor(pColor);
		pColor->Release();
	}

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pCurveDis->GetFillColorR()*255), (long)(pCurveDis->GetFillColorG()*255), (long)(pCurveDis->GetFillColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}
		COleSafeArray saLoop0, saLoop1, saLoop2;				
		saLoop0.CreateOneDim(VT_DISPATCH, 1, &pLine0);
		saLoop1.CreateOneDim(VT_DISPATCH, 1, &pLine1);
		saLoop2.CreateOneDim(VT_DISPATCH, 1, &pLine2);
		VARIANT * pvLoop0=(LPVARIANT)saLoop0;
		VARIANT * pvLoop1=(LPVARIANT)saLoop1;
		VARIANT * pvLoop2=(LPVARIANT)saLoop2;
		pHatch->AppendOuterLoop(*pvLoop0);
		pHatch->AppendOuterLoop(*pvLoop1);
		pHatch->AppendOuterLoop(*pvLoop2);
		pHatch->Release();			
	}
	// 	CCurveObj* curveObj = (CCurveObj*)pCurveDis->GetEntityObj();
	// 	vector<HPoint> points;
	// 	points.push_back(HPoint(curveObj->GetStartPosX(),curveObj->GetStartPosY() ));
	// 	points.push_back(HPoint(curveObj->GetFirPosX(), curveObj->GetFirPosY() ));
	// 	points.push_back(HPoint(curveObj->GetSecPosX(),curveObj->GetSecPosY() ));
	// 	points.push_back(HPoint(curveObj->GetEndPosX(), curveObj->GetEndPosY() ));
	// 	int n = points.size();
	// 	const int m = 3*n;
	// 	if (m > 0)
	// 	{
	// 		double *pts = new double[m];
	// 		for (int i = 0;i < n;i++)
	// 		{
	// 			pts[3*i + 0] = points.at(i).x + m_dblViewOffset;
	// 			pts[3*i + 1] = points.at(i).y;
	// 			pts[3*i + 2] = 0.0;
	// 		}
	// 		COleSafeArray   saPts;
	// 		saPts.CreateOneDim(VT_R8, m, pts); 
	// 		VARIANT * pvPts =  (LPVARIANT)saPts;
	// 		IAcadPolyline *pPolyline=NULL;
	// 		m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	// 		pPolyline->put_Closed(VARIANT_TRUE);
	// 		IAcadAcCmColor *pColor=GetColor();
	// 		if(pColor)
	// 		{
	// 			pColor->SetRGB((long)(pCurveDis->GetColorR()*255), (long)(pCurveDis->GetColorG()*255), (long)(pCurveDis->GetColorB()*255));
	// 			pPolyline->put_TrueColor(pColor);
	// 			pColor->Release();
	// 		}
	// 
	// 		IAcadHatch *pHatch=NULL;
	// 		m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	// 		if(pHatch)
	// 		{
	// // 			IAcadAcCmColor *pColor=GetColor();
	// // 			if(pColor)
	// // 			{
	// // 				pColor->SetRGB((long)(pCurveDis->GetFillColorR()*255), (long)(pCurveDis->GetFillColorG()*255), (long)(pCurveDis->GetFillColorB()*255));
	// // 				pHatch->put_TrueColor(pColor);
	// // 				pColor->Release();
	// // 			}
	// 			COleSafeArray saLoop;				
	// 			saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
	// 			VARIANT * pvLoop=(LPVARIANT)saLoop;
	// 			pHatch->AppendOuterLoop(*pvLoop);
	// 			pHatch->Release();			
	// 		}
	// 		delete []pts;
	// 	}	
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportWordDis(IAcadModelSpace *pModelSpace,CWordDisplayObj* pWordDis) const
{
	if(!pModelSpace)
		return false;
	CString szContent = pWordDis->GetWordText();
	double dblLeft,dblRight,dblTop,dblBottom;
	dblLeft = dblRight = dblTop = dblBottom = 0;
	pWordDis->GetBox(dblLeft,dblBottom,dblRight,dblTop);
	double dblWidth,dblHeight;
	dblWidth = dblRight-dblLeft;
	dblHeight = dblTop - dblBottom;
	HPoint sPt = pWordDis->getEndPos();
	double dblPosX = sPt.x;
	double dblPosY = sPt.y;
	//	int bkTypte = pWordDis->GetBkType();
	double dblTextSize = pWordDis->GetTextSize();
	// 	if (bkTypte ==	BG_QUAD)
	// 	{
	// 		//画方框
	// 		double titlePts[]={	dblPosX-dblWidth/2, dblPosY-dblTextSize, 0,
	// 			dblPosX+dblWidth/2, dblPosY-dblTextSize, 0,
	// 			dblPosX+dblWidth/2, dblPosY+dblTextSize, 0,
	// 			dblPosX-dblWidth/2, dblPosY+dblTextSize, 0,
	// 		};
	// 		COleSafeArray  saTitlePts;
	// 		saTitlePts.CreateOneDim(VT_R8, 12, titlePts);        
	// 		VARIANT * pvTitlePt =  (LPVARIANT)saTitlePts;
	// 		IAcadPolyline *pPolyline=NULL;
	// 		m_pModelSpace->AddPolyline(*pvTitlePt, &pPolyline);
	// 		pPolyline->put_Closed(VARIANT_TRUE);
	// 		IAcadAcCmColor *pColor=GetColor();
	// 		if(pColor)
	// 		{
	// 			pColor->SetRGB((long)(pTextNoteDisObj->GetColorR()*255), (long)(pTextNoteDisObj->GetColorG()*255), (long)(pTextNoteDisObj->GetColorB()*255));
	// 			pPolyline->put_TrueColor(pColor);
	// 			pColor->Release();
	// 		}
	// 	}

	//多行注释则导出为MText
	if (szContent.Find(_T("\n"))!=-1)
	{
		double insert_pts[]={dblLeft, dblTop, 0};

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		IAcadMText* pMText = NULL;
		m_pModelSpace->AddMText(*pvInsertPts,dblWidth,bstr_t(szContent),&pMText);
		if(pMText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pWordDis->GetTextColorR()*255), (long)(pWordDis->GetTextColorG()*255), (long)(pWordDis->GetTextColorB()*255));
				pMText->put_TrueColor(pColor);
				pColor->Release();
			}
			pMText->put_Height(dblTextSize);
			pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointTopLeft);

			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pWordDis->GetTextFont());
			if(!strTextStyle.IsEmpty())
				pMText->put_StyleName(_bstr_t(strTextStyle));
			pMText->Release();
		}

	}
	else//单行注释
	{
		double insert_pts[]={dblPosX+dblWidth/4, dblPosY, 0};

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
		IAcadText *pText=NULL;
		m_pModelSpace->AddText(bstr_t(szContent), *pvInsertPts, dblHeight, &pText);
		if(pText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{

				pColor->SetRGB((long)(pWordDis->GetTextColorR()*255), (long)(pWordDis->GetTextColorG()*255), (long)(pWordDis->GetTextColorB()*255));
				pText->put_TrueColor(pColor);
				pColor->Release();
			}

			if (true)
			{
				pText->put_Alignment(AutoCAD::acAlignmentMiddle);
				pText->put_TextAlignmentPoint(*pvInsertPts);
			}
			else
			{
				pText->put_Alignment(AutoCAD::acAlignmentMiddle);
				pText->put_TextAlignmentPoint(*pvInsertPts);
				pText->put_Rotation(PI*0.5);
			}

			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pWordDis->GetTextFont());
			if(!strTextStyle.IsEmpty())
				pText->put_StyleName(_bstr_t(strTextStyle));

			pText->Release();
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportGroundPatternWordDis(IAcadModelSpace *pModelSpace,CWordDisplayObj* pWordDis) const
{
	if(!pModelSpace)
		return false;
	CWordObj* pWord = (CWordObj*)pWordDis->GetEntityObj();
	CGroundPatternObj *pParent=(CGroundPatternObj *)pWord->GetParentEntity();
	long layerId = pWordDis->GetLayerId();
	CGroundPatternDisObj *pParentDis=(CGroundPatternDisObj *)pParent->GetDisplayObjByLayerID(layerId);
	double  dblLeft,  dblBottom,  dblRight,  dblTop;
	pParentDis->GetBox(dblLeft,  dblBottom,  dblRight,  dblTop);
	CString szContent = pWord->GetText();
	double dblTextSize = pWord->GetFontSize();
	double dblPosX = pWord->GetPosX();
	double dblPosY = pWord->GetPosY() ;
	dblPosX = ( dblPosX + dbTranslate_x ) * dbScale_x + dbTranslateBack_x + m_dblViewOffset + 0.5*dblTextSize;
	dblPosY = (dblPosY + dbTranslate_y) * iV * dbScale_y + dbTranslateBack_y;

	double insert_pts[]={dblPosX, dblPosY, 0};

	COleSafeArray   saInsertPts;
	saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
	VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
	IAcadText *pText=NULL;
	m_pModelSpace->AddText(bstr_t(szContent), *pvInsertPts, dblTextSize, &pText);
	if(pText)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pParentDis->GetTextColorR()*255), (long)(pParentDis->GetTextColorG()*255), (long)(pParentDis->GetTextColorB()*255));
			pText->put_TrueColor(pColor);
			pColor->Release();
		}

		pText->put_Alignment(AutoCAD::acAlignmentMiddleLeft);
		pText->put_TextAlignmentPoint(*pvInsertPts);
		CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pParentDis->GetTextFont());
		if(!strTextStyle.IsEmpty())
			pText->put_StyleName(_bstr_t(strTextStyle));
		pText->Release();
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportImageDis( IAcadModelSpace *pModelSpace,CImageDisplayObj* pImageDis ) const
{
	if(!pModelSpace)
		return false;
	double x0 = pImageDis->getStartPos().x + m_dblViewOffset;
	double y0 = pImageDis->getStartPos().y;
	double x1 = pImageDis->getEndPos().x + m_dblViewOffset;
	double y1 = pImageDis->getEndPos().y;
	float dMinX = 0.5*(x0+x1)-0.5*(fabs(x0-x1));
	float dMinY = 0.5*(y0+y1)-0.5*(fabs(y0-y1));
	float dMaxX = 0.5*(x0+x1)+0.5*(fabs(x0-x1));
	float dMaxY = 0.5*(y0+y1)+0.5*(fabs(y0-y1));
	float width = dMaxX - dMinX;
	float height = dMaxY - dMinY;
	//title
	// 		double ptsTitle[]={dMinX,dMinY+0.9*height,0.0,
	// 			dMaxX,dMinY+0.9*height,0.0,
	// 			dMaxX,dMaxY,0.0,
	// 			dMinX,dMaxY,0.0};
	// 		COleSafeArray   saPtsTitle;
	// 		saPtsTitle.CreateOneDim(VT_R8, 12, ptsTitle); 
	// 		VARIANT * pvPtsTitle =  (LPVARIANT)saPtsTitle;
	// 		IAcadPolyline *pPolyline=NULL;
	// 		m_pModelSpace->AddPolyline(*pvPtsTitle, &pPolyline);
	// 		pPolyline->put_Closed(VARIANT_TRUE);
	// 		IAcadAcCmColor *pColor=GetColor();
	// 		if(pColor)
	// 		{
	// 			pColor->SetRGB((long)(pImageDis->GetColorR()*255), (long)(pImageDis->GetColorG()*255), (long)(pImageDis->GetColorB()*255));
	// 			pPolyline->put_TrueColor(pColor);
	// 			pColor->Release();
	// 		}
	// 
	// 		IAcadHatch *pHatch=NULL;
	// 		m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	// 		if(pHatch)
	// 		{
	// 			IAcadAcCmColor *pColor=GetColor();
	// 			if(pColor)
	// 			{
	// 				pColor->SetRGB((long)(pImageDis->GetFillColorR()*255), (long)(pImageDis->GetFillColorG()*255), (long)(pImageDis->GetFillColorB()*255));
	// 				pHatch->put_TrueColor(pColor);
	// 				pColor->Release();
	// 			}
	// 			COleSafeArray saLoop;				
	// 			saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
	// 			VARIANT * pvLoop=(LPVARIANT)saLoop;
	// 			pHatch->AppendOuterLoop(*pvLoop);
	// 			pHatch->Release();			
	// 		}
	// 		
	// 		//文字		
	// 		double insert_pts[]={0.5*(dMinX+dMaxX), dMinY+0.93*height, 0};
	// 		COleSafeArray   saInsertPts;
	// 		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
	// 		VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
	// 		IAcadMText *pMText=NULL;
	// 		m_pModelSpace->AddMText(*pvInsertPts, width, _bstr_t(_T("图片")), &pMText);  //加宽防止文字过长，出现多行现象
	// 		if(pMText)
	// 		{
	// 			pColor=GetColor();
	// 			if(pColor)
	// 			{
	// 				pColor->SetRGB(0, 255, 0);
	// 				pMText->put_TrueColor(pColor);
	// 				pColor->Release();
	// 			}
	// 			pMText->put_Height(0.15*height);
	// 			pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
	// 
	// 			CString strTextFont=pImageDis->GetTextFont();
	// 			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
	// 			if(!strTextStyle.IsEmpty())
	// 				pMText->put_StyleName(_bstr_t(strTextStyle));
	// 			pMText->Release();
	// 		}

	//body
	double ptsBody[]={dMinX,dMinY,0.0,
		dMaxX,dMinY,0.0,
		dMaxX,dMaxY/* - 0.1*height*/,0.0,
		dMinX,dMaxY/* - 0.1*height*/,0.0};
	COleSafeArray   saPtsBody;
	saPtsBody.CreateOneDim(VT_R8, 12, ptsBody); 
	VARIANT * pvPtsBody =  (LPVARIANT)saPtsBody;
	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPtsBody, &pPolyline);
	pPolyline->put_Closed(VARIANT_TRUE);
	if ( !pPolyline  )
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pImageDis->GetFillColorR()*255), (long)(pImageDis->GetFillColorG()*255), (long)(pImageDis->GetFillColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pImageDis->GetFillColorR()*255), (long)(pImageDis->GetFillColorG()*255), (long)(pImageDis->GetFillColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}
		COleSafeArray saLoop;				
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pPolyline);
		VARIANT * pvLoop=(LPVARIANT)saLoop;
		pHatch->AppendOuterLoop(*pvLoop);
		pHatch->Release();			
	}

	//image
	CImageObj* pImageObj = dynamic_cast<CImageObj*>(pImageDis->GetEntityObj());
	if(pImageObj && !pImageObj->GetPathName().IsEmpty())
	{
		double insert_pts[]={dMinX, dMinY, 0};

		COleSafeArray   saInsertPts;
		saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
		VARIANT * pvInsertPt =  (LPVARIANT)saInsertPts;

		CString strPicFile(pImageObj->GetPathName());
		//int nIndex=strPicFile.Find(_T(':'));
		//if(nIndex!=-1 && nIndex>1)
		//	strPicFile=strPicFile.Mid(nIndex-1);
		//CFile f;
		//f.Open(strPicFile, )
		CImageProp *pImageProp=pImageObj->GetBigDrawing()->GetImageProp(strPicFile);
		if(pImageProp)
		{
			int nIndex=strPicFile.ReverseFind(_T('\\'));
			if(nIndex!=-1 && nIndex+1<strPicFile.GetLength())
			{
				CString strNewPicFile=strPicFile.Mid(nIndex+1);
				CString strExportDir = CModelObjOption::GetExportPicPath();
				if (strExportDir.ReverseFind(_T('\\')) != strExportDir.GetLength() - 1)
				{
					strExportDir = strExportDir + _T("\\");
				}
				strNewPicFile=strExportDir+strNewPicFile;
				pImageProp->Save(strNewPicFile);

				IAcadRasterImage *pImage=NULL;
				m_pModelSpace->AddRaster(_bstr_t(strNewPicFile), *pvInsertPt, 1.0, 0, &pImage);
				if(pImage)
				{
					pImage->put_ImageWidth(width);
					pImage->put_ImageHeight(height);

					pImage->Release();
				}
			}
		}
	}	
	return true;
}

//dsq:用来显示分层导出对话框界面变化的函数

void ACAD_EXPORT_TOOL_COMMON_IMPL::ShowInterfaceInfo(NumInfo* pNumInfo,CString szTxt,CExportProgressDlg *pProgressDlg)
{
	if(pProgressDlg)
	{
		pProgressDlg->SetPrompt(szTxt);
		pProgressDlg->StepIt();
	}
	else
	{
		if (pNumInfo)
		{
			pNumInfo->pStatic->SetWindowTextW(szTxt);			
			m_lProgressPos++;
			pNumInfo->m_Progress->SetPos(m_lProgressPos);					
		}		
	}	
}


bool  ACAD_EXPORT_TOOL_COMMON_IMPL::IsStopLayerExport()
{
	if (m_pNumInfo&&m_pNumInfo->m_bStop)
	{
		m_pNumInfo->pStartBtn->EnableWindow(FALSE);
		m_pNumInfo->pStopBtn->EnableWindow(FALSE);
		m_pNumInfo->pStatic->SetWindowTextW(_T("取消导出..."));
		m_pNumInfo->pListLayer->clear();
		m_pNumInfo->m_Progress->SetPos(0);
		return  true;
	}
	if (!IsAutoCadRightState())
	{
		return  true;
	}
	return false;
}

//void ACAD_EXPORT_TOOL_COMMON_IMPL::ExportGroundPatterns(CLayer* pLayer, IAcadModelSpace * m_pModelSpace)
//{
//	long lLayerId=pLayer->GetId();
//	CSystem *pSystem=pLayer->GetBigDrawing();
//
//	const std::list<CSubSystem *> & SubSystemList=pSystem->GetSubSystemList();
//	std::list<CSubSystem *>::const_iterator it_subsystem;
//	for(it_subsystem=SubSystemList.begin(); it_subsystem!=SubSystemList.end(); ++it_subsystem)
//	{
//		CSubSystem *pSubSystem=*it_subsystem;	
//		const std::list<CDevice *> &DeviceList=pSubSystem->GetDeviceList();
//		std::list<CDevice *>::const_iterator it_device;
//		for(it_device=DeviceList.begin(); it_device!=DeviceList.end(); ++it_device)
//		{
//			CDevice *pDevice=*it_device;
//			CDeviceDisplayObj *pDeviceDisplayObj=(CDeviceDisplayObj *)pDevice->GetDisplayObjByLayerID(lLayerId);
//
//			if(pDeviceDisplayObj && pDeviceDisplayObj->IsShowThis())
//			{
//				std::list<CGroundPatternObj*>  lstGroundUnits = pDevice->GetGroundPatternObjList() ;
//				for (std::list<CGroundPatternObj*>::iterator iter1 = lstGroundUnits.begin();	iter1 != lstGroundUnits.end();	++iter1)
//				{
//					CGroundPatternObj* obj = *iter1;
//					CGroundPatternDisObj* disObj = (CGroundPatternDisObj*)obj->GetDisplayObjByLayerID(lLayerId);
//// 					std::list<CShape*> lstShapes = obj->GetShapeList();
//// 					ExportShapeDisObj(pLayer, m_pModelSpace, nullptr, lLayerId, lstShapes);
//					eGroundPatternType typ = obj->GetGroundPatternType();
//					if (typ == GROUNDPATTERN_DEVSEHELL_STRUCTGND_RESISTOR)
//					{
//						ExportGroundPatternSTructGndResistor(pDeviceDisplayObj, m_pModelSpace, disObj);
//					}
//					else if (typ == GROUNDPATTERN_DEVSEHELL_STRUCTGND_CONNECTED)
//					{
//						ExportGroundPatternSTructGndConnected(pDeviceDisplayObj, m_pModelSpace, disObj);
//					}
//				}
//			}
//		}
//	}
//}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportGroundPatternSTructGndConnected(CDeviceDisplayObj * pDevDisObj,IAcadModelSpace *pModelSpace,CGroundPatternDisObj *pDisplayObj)
{
	if (IsStopLayerExport())
		return false;
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportGroundPatternSTructGndResistor(CDeviceDisplayObj * pDevDisObj,IAcadModelSpace *pModelSpace,CGroundPatternDisObj *pDisplayObj)
{
	if (IsStopLayerExport())
		return false;
	double leftPt, bottonPt, rightPt, topPt;
	pDevDisObj->GetBox(leftPt, bottonPt, rightPt, topPt);
	double dblPosX=(leftPt + rightPt)/2.0 + (pDisplayObj->GetBoxMaxX() + pDisplayObj->GetBoxMinX())/2.0;
	double dblPosY=(bottonPt + topPt)/2.0 + (pDisplayObj->GetBoxMaxY());
	//接地桩几个点，相对大图中的原本的位置
	double pt0[3]={dblPosX,dblPosY,0.0};
	double pt1[3]={dblPosX,dblPosY-3,0.0};
	double pt2[3]={dblPosX-1,dblPosY-4,0.0};
	double pt3[3]={dblPosX+1,dblPosY-6,0.0};
	double pt4[3]={dblPosX-1,dblPosY-8,0.0};
	double pt5[3]={dblPosX+1,dblPosY-10,0.0};
	double pt6[3]={dblPosX-1,dblPosY-12,0.0};
	double pt7[3]={dblPosX+1,dblPosY-14,0.0};
	double pt8[3]={dblPosX,dblPosY-15,0.0};
	double pt9[3]={dblPosX,dblPosY-17,0.0};
	double pt10[3]={dblPosX-2,dblPosY-17,0.0};
	double pt11[3]={dblPosX+2,dblPosY-17,0.0};
	double pt12[3]={dblPosX-3,dblPosY-20,0.0};
	double pt13[3]={dblPosX-1,dblPosY-20,0.0};
	double pt14[3]={dblPosX+1,dblPosY-20,0.0};
	//导出接地桩的N条线
	bool bRet = true;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt0,pt1);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt1,pt2);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt2,pt3);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt3,pt4);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt4,pt5);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt5,pt6);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt6,pt7);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt7,pt8);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt8,pt9);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt10,pt11);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt10,pt12);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt9,pt13);
	if(!bRet)	return false;
	bRet =  ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt11,pt14);
	if(!bRet)	return false;

	return true;
}

//导出接地图元

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportGroundUnit(CLayer* pLayer, IAcadModelSpace * m_pModelSpace )
{
	if (IsStopLayerExport())
		return false;
	//	
	long lLayerId=pLayer->GetId();
	CSystem *pSystem=pLayer->GetBigDrawing();

	const std::list<CSubSystem *> & SubSystemList=pSystem->GetSubSystemList();
	std::list<CSubSystem *>::const_iterator it_subsystem;
	for(it_subsystem=SubSystemList.begin(); it_subsystem!=SubSystemList.end(); ++it_subsystem)
	{
		CSubSystem *pSubSystem=*it_subsystem;	
		const std::list<CDevice *> &DeviceList=pSubSystem->GetDeviceList();
		std::list<CDevice *>::const_iterator it_device;
		for(it_device=DeviceList.begin(); it_device!=DeviceList.end(); ++it_device)
		{
			CDevice *pDevice=*it_device;
			const CDeviceDisplayObj *pDeviceDisplayObj=(CDeviceDisplayObj *)pDevice->GetDisplayObjByLayerID(lLayerId);

			if(pDeviceDisplayObj && pDeviceDisplayObj->IsShowThis())
			{
				//输出接地桩	
				std::list<CGroundUnit*> lstGndUnit = pDevice->GetGroundUnitList();
				std::list<CGroundUnit*>::const_iterator it_GndUnit = lstGndUnit.begin(); 
				for (;it_GndUnit!=lstGndUnit.end();it_GndUnit++)
				{
					CGroundUnit* pGndUnit = *it_GndUnit;

					CGroundUnitDisObj* pGndUnitDis = (CGroundUnitDisObj*)pGndUnit->GetDisplayObjByLayerID(lLayerId);
					int ntype=pGndUnitDis->GetDisplayObjType();
					if (ntype==GROUND_UNIT_DIS_OBJ)
					{ 				
						CGround * pGnd=(CGround *)pGndUnit;
						CGroundDisplayObj *pDisplayObj=(CGroundDisplayObj*)pGnd->GetDisplayObjByLayerID(lLayerId);				

						ExportChassisGround(m_pModelSpace,pDisplayObj);
					}
				}	
			}
		}		
	}	
	return true;
}

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportGroundUnit_RegionManager(CLayer* pLayer, IAcadModelSpace * m_pModelSpace )
{
	if (IsStopLayerExport())
		return false;
	//	
	long lLayerId=pLayer->GetId();
	CSystem *pSystem=pLayer->GetBigDrawing();
	map<CString, CGround *> mapGrounds = pSystem->GetRegionGroundLinkManager()->GetGroundsMap();
	map<CString, CGround *>::iterator iter = mapGrounds.begin();
	for (;iter!=mapGrounds.end();iter++)
	{
		CGround* pGndUnit =iter->second;
		CGroundDisplayObj *pDisplayObj=(CGroundDisplayObj*)pGndUnit->GetDisplayObjByLayerID(lLayerId);				
		ExportChassisGround(m_pModelSpace,pDisplayObj);
	}

	return true;
}

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportGroundPatterns(CLayer* pLayer,IAcadModelSpace *pModelSpace/*, CGroundPatternObj *pLayout, long lLayerId, double mat[16]*//*=NULL*/)
{
	if (IsStopLayerExport())
		return false;
	bDoTranslate = true;
	long lLayerId=pLayer->GetId();
	CSystem *pSystem=pLayer->GetBigDrawing();

	const std::list<CSubSystem *> & SubSystemList=pSystem->GetSubSystemList();
	std::list<CSubSystem *>::const_iterator it_subsystem;
	for(it_subsystem=SubSystemList.begin(); it_subsystem!=SubSystemList.end(); ++it_subsystem)
	{
		CSubSystem *pSubSystem=*it_subsystem;	
		const std::list<CDevice *> &DeviceList=pSubSystem->GetDeviceList();
		std::list<CDevice *>::const_iterator it_device;
		for(it_device=DeviceList.begin(); it_device!=DeviceList.end(); ++it_device)
		{
			CDevice *pDevice=*it_device;
			const CDeviceDisplayObj *pDeviceDisplayObj=(CDeviceDisplayObj *)pDevice->GetDisplayObjByLayerID(lLayerId);

			if(pDeviceDisplayObj && pDeviceDisplayObj->IsShowThis())
			{
				//输出接地桩	
				std::list<CGroundPatternObj*> lstGndPatterns = pDevice->GetGroundPatternObjList();
				std::list<CGroundPatternObj*>::const_iterator it_GndPattern = lstGndPatterns.begin(); 
				for (;it_GndPattern!=lstGndPatterns.end();it_GndPattern++)
				{
					CGroundPatternObj* pGndPattern = *it_GndPattern;

					CGroundPatternDisObj* pGndPatternDis = (CGroundPatternDisObj*)pGndPattern->GetDisplayObjByLayerID(lLayerId);
					if (!pGndPatternDis)
					{
						continue;
					}
					//矩阵变换，将电路图填充到设备
					double origin_box_width = pGndPattern->GetBoxMaxX() - pGndPattern->GetBoxMinX();
					double origin_box_height = pGndPattern->GetBoxMaxY() - pGndPattern->GetBoxMinY();
					double origin_box_centerX = 0.5*(pGndPattern->GetBoxMinX() + pGndPattern->GetBoxMaxX());
					double origin_box_centerY = 0.5*(pGndPattern->GetBoxMinY() + pGndPattern->GetBoxMaxY());	
					//求电路图包围盒(带有余量)
					double boxLeft, boxBottom, boxRight, boxTop;
					pGndPatternDis->GetBox(boxLeft, boxBottom, boxRight, boxTop);
					double box_width = boxRight - boxLeft;
					double box_height = boxTop - boxBottom;
					double center_x = 0.5*(boxLeft + boxRight);
					double center_y = 0.5*(boxBottom + boxTop);

					//移动到原点位置

					dbTranslate_x = 0.0-origin_box_centerX;
					dbTranslate_y = 0.0-origin_box_centerY;
					//					Translate_GroundPattern(pGndPatternDis, 0.0-origin_box_centerX, 0.0-origin_box_centerY);
					//由于坐标系问题，首先要翻转180度 

					//					dbRotateAng = 180.0;
					//					Rotate_GroundPattern( pGndPatternDis, 180);
					//旋转（如果有）
					//...........
					iV = -1;
					//比例缩放到设备边框大小
					double x_scale = box_width/origin_box_width;
					double y_scale = box_height/origin_box_height;

					dbScale_x = x_scale;
					dbScale_y = y_scale;
					//					Scale_GroundPattern(pGndPatternDis, x_scale, y_scale);

					//移动到设备上
					eGroundPatternType patternTyp = pGndPattern->GetGroundPatternType();
					int nOffset=3;
					if (pGndPatternDis->IsStructGnd())
					{
						double boxLeftDev, boxBottomDev, boxRightDev, boxTopDev;
						pDeviceDisplayObj->GetBox(boxLeftDev, boxBottomDev, boxRightDev, boxTopDev);
						if (boxRight>boxRightDev)
						{
							center_x = boxRightDev-0.5*box_width-nOffset;
							pGndPatternDis->SetBoxMaxX( 0.5*box_width);
							pGndPatternDis->SetBoxMinX(-0.5*box_width);
						}
						if (boxLeft<boxLeftDev)
						{
							center_x = boxLeftDev+0.5*box_width+nOffset;
							pGndPatternDis->SetBoxMaxX( 0.5*box_width);
							pGndPatternDis->SetBoxMinX(-0.5*box_width);
						}
						center_y=pDeviceDisplayObj->GetPosY()-pDeviceDisplayObj->GetHeight()/2-pGndPatternDis->GetHeight()/2;
					}
					else if (pGndPatternDis->IsWireAndShellGnd())
					{
						double boxLeftDev, boxBottomDev, boxRightDev, boxTopDev;
						pDeviceDisplayObj->GetBox(boxLeftDev, boxBottomDev, boxRightDev, boxTopDev);
						if (boxRight>boxRightDev)
						{
							center_x = boxRightDev-0.5*box_width-nOffset;
							pGndPatternDis->SetBoxMaxX( 0.5*box_width);
							pGndPatternDis->SetBoxMinX( -0.5*box_width);
						}
						if (boxLeft<boxLeftDev)
						{
							center_x = boxLeftDev+0.5*box_width+nOffset;
							pGndPatternDis->SetBoxMaxX( 0.5*box_width);
							pGndPatternDis->SetBoxMinX( -0.5*box_width);
						}
						center_y=pDeviceDisplayObj->GetPosY()-pDeviceDisplayObj->GetHeight()/2+pGndPatternDis->GetHeight()/2;
					}
					else if (patternTyp == GROUNDPATTERN_DEV_INSIDE_TRANS_ISOLATION)
					{//设备自带电源（个数为1）和变压器隔离接地符号重叠显示
						center_y+=1.5*nOffset;
					}
					dbTranslateBack_x = center_x;
					dbTranslateBack_y = center_y;
					//					Translate_GroundPattern(pGndPatternDis, center_x, center_y);

					//switch(patternTyp)
					//{
					//	//一次二次回线连接方式：
					//case GROUNDPATTERN_FirAndSec_CONNECTED://一次和二次回线连通
					//		case GROUNDPATTERN_FirAndSec_RESISTOR:  //一次和二次回线高阻
					//		case GROUNDPATTERN_FirAndSec_ISOLATION://一次和二次回线隔离
					//		//一次回线与设备壳体连接方式：
					//		case GROUNDPATTERN_FirAndEdviceSheel_ISOLATION://一次回线与设备壳体隔离
					//		case GROUNDPATTERN_FirAndEdviceSheel_RESISTOR://一次回线通过开关与电阻并联结构接壳
					//		case GROUNDPATTERN_FirAndEdviceSheel_CONNECTED://一次回线与设备壳体连通
					//		//设备内部自带DC/DC模块：
					//		case GROUNDPATTERN_DEV_INSIDE_DCDC:
					//		//设备隔离设计
					//		case GROUNDPATTERN_DEV_INSIDE_TRANS_ISOLATION://设备内部变压器隔离
					//		case GROUNDPATTERN_DEV_INSIDE_PHOTOCOUPLER_ISOLATION://设备内部光耦隔离
					//		//二次回线与设备壳体连接方式：
					//		case GROUNDPATTERN_SecAndDEVSEHELL_ISOLATION: //二次回线与机壳隔离
					//		case GROUNDPATTERN_SecAndDEVSEHELL_SINGLE_GND: //二次回线与机壳单点接地
					//		case GROUNDPATTERN_SecAndDEVSEHELL_MORE_GND:   //二次回线与机壳多点接地
					//		case GROUNDPATTERN_SecAndDEVSEHELL_RESISTOR_GND:  //二次回线与机壳高阻接地
					//		//设备壳体与整星结构地连接方式：
					//		case GROUNDPATTERN_DEVSEHELL_STRUCTGND_CONNECTED: //设备壳体与整星结构地连通
					//		case GROUNDPATTERN_DEVSEHELL_STRUCTGND_ISOLATION: //设备壳体在整星结构处绝缘安装
					//		case GROUNDPATTERN_DEVSEHELL_STRUCTGND_RESISTOR:  //设备壳体在整星结构处高阻接地

					//		default:
					//			continue;
					//}
					std::list<CShape*> lstShapes = pGndPattern->GetShapeList();
					ExportShapeDisObj(pLayer, m_pModelSpace, NULL, lLayerId, lstShapes);
				}	
			}
		}		
	}	
	bDoTranslate = false;
	InitGroundPatternParams();
	return true;
}

//导出接地桩

bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportChassisGround(IAcadModelSpace *pModelSpace,CGroundDisplayObj *pDisplayObj)
{
	if (IsStopLayerExport())
		return false;
	eGroundType type =pDisplayObj->GetGroundType();
	if(type==CHASSIS_GROUND)
	{
		double dblPosX=pDisplayObj->GetPosX();
		double dblPosY=pDisplayObj->GetPosY();
		//接地桩几个点，相对大图中的原本的位置
		double pt1[3]={dblPosX,dblPosY,0.0};
		double pt2[3]={dblPosX,dblPosY-10,0.0};
		double pt3[3]={dblPosX-10,dblPosY-10,0.0};
		double pt4[3]={dblPosX+10,dblPosY-10,0.0};
		double pt5[3]={dblPosX-15,dblPosY-20,0.0};
		double pt6[3]={dblPosX-5,dblPosY-20,0.0};
		double pt7[3]={dblPosX+5,dblPosY-20,0.0};
		//导出接地桩的5条线
		bool bRet = ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt1,pt2);
		if(!bRet)	return false;
		bRet = ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt3,pt4);
		if(!bRet)	return false;
		bRet = ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt3,pt5);
		if(!bRet)	return false;
		bRet = ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt2,pt6);
		if(!bRet)	return false;
		bRet = ExportChassisGroundLine(m_pModelSpace,pDisplayObj,pt4,pt7);
		if(!bRet)	return false;

		CGround* pGround = (CGround*)pDisplayObj->GetEntityObj();
		CString  sIndex = pGround->GetGroundIndex();
		if ( !sIndex.IsEmpty())
		{
			COleSafeArray   saInsertPts;
			VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
			IAcadMText *pMText=NULL;
			int nWidth = 10*pDisplayObj->GetTextSize();
			double insert_pts[]={dblPosX-0.5*nWidth, dblPosY-25, 0};
			saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
			pvInsertPts =  (LPVARIANT)saInsertPts;
			pMText=NULL;
			m_pModelSpace->AddMText(*pvInsertPts, nWidth, _bstr_t(sIndex), &pMText);
			if(pMText)
			{
				IAcadAcCmColor *pColor=GetColor();
				if(pColor)
				{
					pColor->SetRGB((long)(pDisplayObj->GetColorR()*255), (long)(pDisplayObj->GetColorG()*255), (long)(pDisplayObj->GetColorB()*255));
					pMText->put_TrueColor(pColor);
					pColor->Release();
				}
				pMText->put_Height(0.8*pDisplayObj->GetTextSize());
				pMText->put_AttachmentPoint(AutoCAD::acAttachmentPointMiddleCenter);
				CString strTextFont=pDisplayObj->GetTextFont();
				CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, strTextFont);
				if(!strTextStyle.IsEmpty())
					pMText->put_StyleName(_bstr_t(strTextStyle));
				pMText->Release();
			}
		}
	}
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportChassisGroundLine(IAcadModelSpace *pModelSpace,CDisplayObj *pDis,double ptStart[3],double ptEnd[3])
{
	if (IsStopLayerExport())
		return false;
	double ptsStart[3]={ptStart[0],ptStart[1],ptStart[2]};
	double ptsEnd[3] = {ptEnd[0],ptEnd[1],ptEnd[2]};
	COleSafeArray   saPtsStart,saPtsEnd;
	saPtsStart.CreateOneDim(VT_R8, 3, ptsStart); 
	saPtsEnd.CreateOneDim(VT_R8, 3, ptsEnd); 
	VARIANT * pvPtsStart =  (LPVARIANT)saPtsStart;
	VARIANT * pvPtsEnd =  (LPVARIANT)saPtsEnd;
	IAcadLine *pLine=NULL;
	m_pModelSpace->AddLine(*pvPtsStart, *pvPtsEnd,&pLine);
	if ( !pLine  )
		return false;
	//
	if (pDis->IsSubCableDisObj())
	{
		//if(pDis->GetLineWidth()>1.0001)
		//pLine->;
		//pLine->put_ConstantWidth(pDis->GetLineWidth()*0.1);//HOOPS与ACAD中宽度的显示效果不同
	}
	//

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pDis->GetColorR()*255), (long)(pDis->GetColorG()*255), (long)(pDis->GetColorB()*255));
		pLine->put_TrueColor(pColor);
		pColor->Release();
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportSubCableTyingPt(IAcadModelSpace *pModelSpace, CSubCableTyingDisObj *pSubCableTyingDis)
{
	if (IsStopLayerExport())
		return false;

	long pts_size=3;
	double pts[]={pSubCableTyingDis->GetPosX(), pSubCableTyingDis->GetPosY(), 0};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, pts_size, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     
	IAcadCircle *pCircle=NULL;
	pModelSpace->AddCircle(*pvPts, pSubCableTyingDis->GetRadius(), &pCircle);
	if (pCircle)  //0717;
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pSubCableTyingDis->GetColorR()*255), (long)(pSubCableTyingDis->GetColorG()*255), (long)(pSubCableTyingDis->GetColorB()*255));
			pCircle->put_TrueColor(pColor);
			pColor->Release();
		}
	}	

	IAcadHatch *pHatch=NULL;
	m_pModelSpace->AddHatch(AutoCAD::acHatchPatternTypePreDefined, _bstr_t("SOLID"), VARIANT_TRUE, vtMissing, &pHatch);
	if(pHatch)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(pSubCableTyingDis->GetFillColorR()*255), (long)(pSubCableTyingDis->GetFillColorG()*255), (long)(pSubCableTyingDis->GetFillColorB()*255));
			pHatch->put_TrueColor(pColor);
			pColor->Release();
		}
		COleSafeArray saLoop;				
		saLoop.CreateOneDim(VT_DISPATCH, 1, &pCircle);
		VARIANT * pvLoop=(LPVARIANT)saLoop;
		pHatch->AppendOuterLoop(*pvLoop);
		pHatch->Release();			
	}				

	return true;	
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCableBranches(IAcadModelSpace *pModelSpace, CSubCableDisplayObj *pSubCableDis)
{
	if (IsStopLayerExport())
		return false;
	list<pair<double, double> > & SegList=pSubCableDis->GetMidPtList();
	list<pair<double, double> >::const_iterator iter_first=SegList.begin();
	list<pair<double, double> >::const_iterator iter_second=SegList.begin();
	iter_second++;
	int nSegIndex=0;
	while(iter_second != SegList.end())
	{
		double pt1[3]={iter_first->first,iter_first->second,0.0};
		double pt2[3]={iter_second->first,iter_second->second,0.0};
		if ( !ExportChassisGroundLine(m_pModelSpace,pSubCableDis,pt1,pt2))
		{
			return false;
		}
		double dAngle=0.0;//旋转的角度值;
		if (iter_second->first!=0)
		{
			dAngle=GetAngle(iter_first->first,iter_first->second,iter_second->first,iter_second->second);
		}

		list<pair<CTextDisplayObj*, CTextDisplayObj*> > lstTextDis;
		pSubCableDis->GetSegTextAndLengthList(nSegIndex,lstTextDis);
		list<pair<CTextDisplayObj*, CTextDisplayObj*> >::iterator iter_text=lstTextDis.begin();
		for(;iter_text!=lstTextDis.end();iter_text++)
		{
			CTextDisplayObj* pTextDisplayObj=iter_text->first;
			CTextDisplayObj* pLenghtDis=iter_text->second;
			if (pTextDisplayObj&&pTextDisplayObj->IsShowThis())
			{
				CString strCableNo = pSubCableDis->GetTextName(false,nSegIndex);
				ExportBranchesSubCableText(m_pModelSpace,pSubCableDis,nSegIndex,pTextDisplayObj,strCableNo,dAngle);
			}
			if (pLenghtDis&&pLenghtDis->IsShowThis())
			{
				CString strCableNo = pSubCableDis->GetTextName(true,nSegIndex);
				ExportBranchesSubCableText(m_pModelSpace,pSubCableDis,nSegIndex,pLenghtDis,strCableNo,dAngle);
			}
		}

		nSegIndex++;
		iter_first++;
		iter_second++;
	}

	return true;	
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportBranchesSubCableText(IAcadModelSpace *pModelSpace, CSubCableDisplayObj *pSubCableDis,int nSegIndex,CTextDisplayObj*pTextDisplayObj,CString strCableNo,double angle) 
{
	if (IsStopLayerExport())
		return false;

	double dblTextHeight=pTextDisplayObj->GetTextSize();
	double x = pTextDisplayObj->GetPosX()+pTextDisplayObj->GetOffsetX();
	double y = pTextDisplayObj->GetPosY()+pTextDisplayObj->GetOffsetY();
	double insert_pts[]={x, y, 0};

	COleSafeArray   saInsertPts;
	saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
	VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
	IAcadText *pText=NULL;
	m_pModelSpace->AddText(bstr_t(strCableNo), *pvInsertPts, dblTextHeight, &pText);
	if(pText)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			if(pTextDisplayObj)
				pColor->SetRGB((long)(pTextDisplayObj->GetTextColorR()*255), (long)(pTextDisplayObj->GetTextColorG()*255), (long)(pTextDisplayObj->GetTextColorB()*255));
			else
				pColor->SetRGB((long)(pSubCableDis->GetTextColorR()*255), (long)(pSubCableDis->GetTextColorG()*255), (long)(pSubCableDis->GetTextColorB()*255));
			pText->put_TrueColor(pColor);
			pColor->Release();
		}

		if (pTextDisplayObj->IsHorizon())
		{
			pText->put_Alignment(AutoCAD::acAlignmentMiddle);
			pText->put_TextAlignmentPoint(*pvInsertPts);
			pText->put_Rotation(angle);
		}
		else
		{
			pText->put_Alignment(AutoCAD::acAlignmentMiddle);
			pText->put_TextAlignmentPoint(*pvInsertPts);
			pText->put_Rotation(PI*0.5);
		}	

		CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pSubCableDis->GetTextFont());
		if(!strTextStyle.IsEmpty())
			pText->put_StyleName(_bstr_t(strTextStyle));
		pText->Release();
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportCableBranchePin(IAcadModelSpace *pModelSpace, const CPinDisplayObj *pPinDisplayObj) 
{
	if (IsStopLayerExport())
		return false;
	double dblPosX=pPinDisplayObj->GetPosX();
	double dblPosY=pPinDisplayObj->GetPosY();

	double dblEndX,dblEndY;
	((CPinDisplayObj *)pPinDisplayObj)->GetEndPos(dblEndX, dblEndY);
	eConnectorSideType eType;
	bool bGetType = ((CPinDisplayObj *)pPinDisplayObj)->GetConnectorSideType(eType);
	if (!bGetType)
		return true;

	double pts[]={	dblPosX, dblPosY, 0,
		dblEndX, dblEndY, 0,
	};

	COleSafeArray   saPts;
	saPts.CreateOneDim(VT_R8, 6, pts);        
	VARIANT * pvPts =  (LPVARIANT)saPts;     

	IAcadPolyline *pPolyline=NULL;
	m_pModelSpace->AddPolyline(*pvPts, &pPolyline);
	pPolyline->put_Closed(VARIANT_FALSE);
	if ( !pPolyline  )
		return false;

	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pPinDisplayObj->GetColorR()*255), (long)(pPinDisplayObj->GetColorG()*255), (long)(pPinDisplayObj->GetColorB()*255));
		pPolyline->put_TrueColor(pColor);
		pColor->Release();
	}
	pPolyline->Release();

	double dblCenterX,dblCenterY;
	double dblRadius=((CPinDisplayObj *)pPinDisplayObj)->GetPinCircleRadius();
	double g_iPinLength =pPinDisplayObj->GetPinLength();
	switch (eType)
	{
	case CONNECTOR_IN_LEFT_OF_PARENT:
		dblCenterX = dblEndX - dblRadius;
		dblCenterY = dblEndY;
		break;

	case CONNECTOR_IN_DOWN_OF_PARENT:
		dblCenterX = dblEndX;
		dblCenterY = dblEndY-dblRadius;
		break;

	case CONNECTOR_IN_RIGHT_OF_PARENT:
		dblCenterX = dblEndX + dblRadius;
		dblCenterY = dblEndY;
		break;

	case CONNECTOR_IN_UP_OF_PARENT:
		dblCenterX = dblEndX;
		dblCenterY = dblEndY + dblRadius;
		break;

	default:
		break;
	}

	COleSafeArray   safeOleArr;
	double   dValues[3]={dblCenterX, dblCenterY, 0};       
	safeOleArr.CreateOneDim(VT_R8,3,dValues);        
	VARIANT   *   pNewPointVariant   =   (LPVARIANT)safeOleArr;     
	IAcadCircle *pCircle=NULL;
	m_pModelSpace->AddCircle(*pNewPointVariant, dblRadius, &pCircle);
	if ( !pCircle  )
		return false;
	pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(pPinDisplayObj->GetColorR()*255), (long)(pPinDisplayObj->GetColorG()*255), (long)(pPinDisplayObj->GetColorB()*255));
		pCircle->put_TrueColor(pColor);
		pColor->Release();
	}
	pCircle->Release();

	{
		IAcadText *pText=NULL;
		CString strCode=pPinDisplayObj->GetAliasName();
		double dblTextHeight=pPinDisplayObj->GetTextSize();
		COleSafeArray   saInsertPts;
		VARIANT * pvInsertPts;

		eConnectorSideType eType;
		bool bGetType = ((CPinDisplayObj *)pPinDisplayObj)->GetConnectorSideType(eType);
		if (bGetType)
		{
			if(eType==CONNECTOR_IN_LEFT_OF_PARENT)
			{
				double x =dblPosX-g_iPinLength;
				double y =dblPosY;
				double insert_pts[]={x, y,-0.2f};
				saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
				pvInsertPts =  (LPVARIANT)saInsertPts;
				m_pModelSpace->AddText(bstr_t(strCode), *pvInsertPts, dblTextHeight, &pText);

				pText->put_Alignment(AutoCAD::acAlignmentRight);
			}
			else if(eType==CONNECTOR_IN_RIGHT_OF_PARENT)
			{
				double x = dblPosX+0.5*g_iPinLength;
				double y = dblPosY;
				double insert_pts[]={x, y,-0.2f};
				saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
				pvInsertPts =  (LPVARIANT)saInsertPts;
				m_pModelSpace->AddText(bstr_t(strCode), *pvInsertPts, dblTextHeight, &pText);
				////将文字平移，按文字的长度平移
				//VARIANT MinPt,MaxPt;
				//pText->GetBoundingBox(&MinPt,&MaxPt);
				//COleSafeArray newMovePt;
				//SAFEARRAY* pSafe = MaxPt.parray;
				//

				//double * pData;
				//SafeArrayAccessData(pSafe, (LPVOID *)&pData);
				//double dVal = *pData;
				//SafeArrayUnaccessData(pSafe);
				//double newMove_pts[]={dVal, y,-0.2f};
				//newMovePt.CreateOneDim(VT_R8, 3, newMove_pts);   

				////pText->Move(MinPt,MaxPt);
				//pText->Move(*pvInsertPts,*((LPVARIANT)newMovePt));

				pText->put_Alignment(AutoCAD::acAlignmentLeft);
			}
			else if(eType==CONNECTOR_IN_UP_OF_PARENT)
			{
				double x= dblPosX;
				double y= dblPosY+0.5*g_iPinLength;
				double insert_pts[]={x, y,-0.2f};
				saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
				pvInsertPts =  (LPVARIANT)saInsertPts;


				m_pModelSpace->AddText(bstr_t(strCode), *pvInsertPts, dblTextHeight, &pText);
				pText->put_Rotation(-PI*0.5);


				pText->put_Alignment(AutoCAD::acAlignmentBottomRight);

			}
			else if(eType==CONNECTOR_IN_DOWN_OF_PARENT)
			{
				double x = dblPosX;
				double y = dblPosY - 0.5*g_iPinLength;
				double insert_pts[]={x, y,-0.2f};
				saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
				pvInsertPts =  (LPVARIANT)saInsertPts;
				m_pModelSpace->AddText(bstr_t(strCode), *pvInsertPts, dblTextHeight, &pText);

				pText->put_Alignment(AutoCAD::acAlignmentTopLeft);
				pText->put_Rotation(-PI*0.5);
			}
			pText->put_TextAlignmentPoint(*pvInsertPts);
		}			


		if(pText)
		{
			IAcadAcCmColor *pColor=GetColor();
			if(pColor)
			{
				pColor->SetRGB((long)(pPinDisplayObj->GetTextColorR()*255), (long)(pPinDisplayObj->GetTextColorG()*255), (long)(pPinDisplayObj->GetTextColorB()*255));
				pText->put_TrueColor(pColor);
				pColor->Release();
			}			

			CString strTextStyle=GetOrCreateTextStyle(m_pModelSpace, pPinDisplayObj->GetTextFont());
			if(!strTextStyle.IsEmpty())
				pText->put_StyleName(_bstr_t(strTextStyle));
			pText->Release();
		}
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportPageTemplate( CLayer* pLayer, IAcadModelSpace * m_pModelSpace )
{
	if (IsStopLayerExport())
		return false;
	if(!pLayer)
	{
		return true;
	}
	CPageTemplateSetup* pPageTempSetup=pLayer->GetPageTemplateSetup();
	if(!pPageTempSetup)
	{
		return true;
	}
	return ExportPageTemplate(m_pModelSpace,pPageTempSetup);
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::ExportPageTemplate( IAcadModelSpace *pModelSpace,CPageTemplateSetup *pPageTempSetup )
{
	if (IsStopLayerExport())
		return false;
	if(!pPageTempSetup || !CModelObjOption::GetShowPageTemplate())
	{
		return true;
	}
	const std::map<ePageTempItemType,PageTempItemInfo>&  mapTempItemType2Info = pPageTempSetup->GetPageTemplateInfoMap();
	std::map<ePageTempItemType,PageTempItemInfo>::const_iterator const_it;
	for(const_it = mapTempItemType2Info.begin(); const_it!=mapTempItemType2Info.end();const_it++)
	{
		DrawRectInCAD(m_pModelSpace,
			const_it->second.m_dLeft,
			const_it->second.m_dRight,
			const_it->second.m_dTop,
			const_it->second.m_dBtm,
			const_it->second.m_dZ,
			1,255,255,255);
		DrawTxtInCAD(m_pModelSpace,
			(const_it->second.m_dLeft+const_it->second.m_dRight)*0.5,
			(const_it->second.m_dTop+const_it->second.m_dBtm)*0.5,
			const_it->second.m_dZ,
			const_it->second.m_szTxt,
			const_it->second.m_dTxtHeight,
			255,255,255);
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::DrawLineInCAD( IAcadModelSpace *pModelSpace,double pts[6], double dblLineWidth, double color_r, double color_g, double color_b )
{
	//画1线段
	double ptsStart[3]={pts[0],pts[1],pts[2]};
	double ptsEnd[3] = {pts[3],pts[4],pts[5]};
	COleSafeArray   saPtsStart,saPtsEnd;
	saPtsStart.CreateOneDim(VT_R8, 3, ptsStart); 
	saPtsEnd.CreateOneDim(VT_R8, 3, ptsEnd); 
	VARIANT * pvPtsStart =  (LPVARIANT)saPtsStart;
	VARIANT * pvPtsEnd =  (LPVARIANT)saPtsEnd;
	IAcadLine *pLine=NULL;
	m_pModelSpace->AddLine(*pvPtsStart, *pvPtsEnd,&pLine);
	if ( !pLine  )
		return false;
	IAcadAcCmColor *pColor=GetColor();
	if(pColor)
	{
		pColor->SetRGB((long)(color_r), (long)(color_g), (long)(color_b));
		pLine->put_TrueColor(pColor);
		pColor->Release();
	}
	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::DrawRectInCAD( IAcadModelSpace *pModelSpace,double dLeft, double dRight,double dTop,double dBtm,double dZ,double dblLineWidth, double color_r, double color_g, double color_b )
{
	double pts1[6] = {
		dLeft,
		dBtm,
		dZ,
		dLeft,
		dTop,
		dZ,
	};
	bool bRet =		DrawLineInCAD(m_pModelSpace,pts1,  dblLineWidth, color_r,  color_g,  color_b );
	if(!bRet)
		return false;
	double pts2[6] = {
		dLeft,
		dTop,
		dZ,
		dRight,
		dTop,
		dZ,
	};
	bRet =		DrawLineInCAD(m_pModelSpace,pts2,  dblLineWidth, color_r,  color_g,  color_b );
	if(!bRet)
		return false;
	double pts3[6] = {
		dRight,
		dTop,
		dZ,
		dRight,
		dBtm,
		dZ,
	};
	bRet =		DrawLineInCAD(m_pModelSpace,pts3,  dblLineWidth, color_r,  color_g,  color_b );
	if(!bRet)
		return false;
	double pts4[6]= {
		dRight,
		dBtm,
		dZ,
		dLeft,
		dBtm,
		dZ,
	};
	bRet =		DrawLineInCAD(m_pModelSpace,pts4,  dblLineWidth, color_r,  color_g,  color_b );
	if(!bRet)
		return false;

	return true;
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::DrawTxtInCAD( IAcadModelSpace *pModelSpace,double dX, double dY,double dZ,CString szContent, double dHeight, double color_r, double color_g, double color_b )
{
	double insert_pts[] = {dX,dY,dZ};
	COleSafeArray   saInsertPts;
	saInsertPts.CreateOneDim(VT_R8, 3, insert_pts);        
	VARIANT * pvInsertPts =  (LPVARIANT)saInsertPts;
	IAcadText *pText=NULL;
	m_pModelSpace->AddText(bstr_t(szContent), *pvInsertPts, dHeight, &pText);
	if(pText)
	{
		IAcadAcCmColor *pColor=GetColor();
		if(pColor)
		{
			pColor->SetRGB((long)(color_r), (long)(color_g), (long)(color_b));
			pText->put_TrueColor(pColor);
			pColor->Release();
		}
		pText->put_Alignment(AutoCAD::acAlignmentMiddleCenter);
		pText->put_TextAlignmentPoint(*pvInsertPts);
	}
	return true;
}


void ACAD_EXPORT_TOOL_COMMON_IMPL::Translate_GroundPattern(CGroundPatternDisObj *disObj, double x, double y)
{
	CGroundPatternObj* obj = (CGroundPatternObj*)disObj->GetEntityObj();
	long layerId = disObj->GetLayerId();
	list<CShape*> lstShapes = obj->GetShapeList();
	for (list<CShape*>::iterator iter = lstShapes.begin(); iter!= lstShapes.end(); ++iter)
	{
		eShapeStyle shapeStyle = (*iter)->getShapeStyle();
		switch(shapeStyle)
		{
		case SHAPE_LINE:
			{
				CLineDisplayObj* lineDisObj = (CLineDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				CLineObj* pLineObj = (CLineObj*)lineDisObj->GetEntityObj();
				pLineObj->SetStartPosX(pLineObj->GetStartPosX() + x);
				pLineObj->SetStartPosY(pLineObj->GetStartPosY() + y);
				pLineObj->SetEndPosX(pLineObj->GetEndPosX() + x);
				pLineObj->SetEndPosY(pLineObj->GetEndPosY() + y);
				break;
			}

		case SHAPE_RECTANGLE:
		case SHAPE_ROUND_RECTANGLE:
		case SHAPE_ELLIPSE:
		case SHAPE_IMAGE:
			{
				CShapeDisplayObj* shapeDisObj = dynamic_cast<CShapeDisplayObj*>((*iter)->GetDisplayObjByLayerID(layerId));
				shapeDisObj->setStartPos(HPoint(shapeDisObj->getStartPos().x + x, shapeDisObj->getStartPos().y + y));
				shapeDisObj->setEndPos(HPoint(shapeDisObj->getEndPos().x + x, shapeDisObj->getEndPos().y + y));

				break;
			}


			// 			CRectangleDisplayObj* shapeDisObj = (CRectangleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 
			// 		
			// 			CRoundRectangleDisplayObj* shapeDisObj = (CRoundRectangleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 
			// 		
			// 			CEllipsDisplayObj* shapeDisObj = (CEllipsDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

		case SHAPE_POLYGON:
			{
				CPolygonDisplayObj* polyDisObj = (CPolygonDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				vector<HPoint> points = polyDisObj->GetAllPoints();
				for (int i = 0; i < points.size(); ++i)
				{
					points[i] = HPoint(points[i].x + x, points[i].y + y);
				}
				polyDisObj->ChangeAllPoints(points);

				break;
			}
		case SHAPE_CURVE:
			{
				CCurveDisplayObj* curveDisObj = (CCurveDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				CCurveObj* curveObj = (CCurveObj*)curveDisObj->GetEntityObj();
				curveObj->SetStartPosX(curveObj->GetStartPosX() + x);
				curveObj->SetStartPosY(curveObj->GetStartPosY() + y);
				curveObj->SetFirPosX(curveObj->GetFirPosX() + x);
				curveObj->SetFirPosY(curveObj->GetFirPosY() + y);
				curveObj->SetSecPosX(curveObj->GetSecPosX() + x);
				curveObj->SetSecPosY(curveObj->GetSecPosY() + y);
				curveObj->SetEndPosX(curveObj->GetEndPosX() + x);
				curveObj->SetEndPosY(curveObj->GetEndPosY() + y);

				break;
			}
			//CImageDisplayObj* shapeDisObj = (CImageDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

			// 		case SHAPE_WORD:
			// 			CWordDisplayObj* shapeDisObj = (CWordDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

			// 		case SHAPE_CURVE:

			// 		case SHAPE_CIRCLE:
			// 			CCircleDisplayObj* shapeDisObj = (CCircleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

			//case SHAPE_POLYLINE:
		default:
			return;
		}

	}
}


void ACAD_EXPORT_TOOL_COMMON_IMPL::Rotate_GroundPattern(CGroundPatternDisObj *disObj, double ang)
{
	if (abs(ang - 180) > 1)
	{
		return;
	}

	CGroundPatternObj* obj = (CGroundPatternObj*)disObj->GetEntityObj();
	long layerId = disObj->GetLayerId();
	list<CShape*> lstShapes = obj->GetShapeList();
	for (list<CShape*>::iterator iter = lstShapes.begin(); iter!= lstShapes.end(); ++iter)
	{
		eShapeStyle shapeStyle = (*iter)->getShapeStyle();
		switch(shapeStyle)
		{
		case SHAPE_LINE:
			{
				CLineDisplayObj* lineDisObj = (CLineDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				CLineObj* pLineObj = (CLineObj*)lineDisObj->GetEntityObj();
				pLineObj->SetStartPosY(-pLineObj->GetStartPosY());
				pLineObj->SetEndPosY(-pLineObj->GetEndPosY());
				break;
			}

		case SHAPE_RECTANGLE:
		case SHAPE_ROUND_RECTANGLE:
		case SHAPE_ELLIPSE:
		case SHAPE_IMAGE:
			{
				CShapeDisplayObj* shapeDisObj = dynamic_cast<CShapeDisplayObj*>((*iter)->GetDisplayObjByLayerID(layerId));
				shapeDisObj->setStartPos(HPoint(shapeDisObj->getStartPos().x, -shapeDisObj->getStartPos().y));
				shapeDisObj->setEndPos(HPoint(shapeDisObj->getEndPos().x, -shapeDisObj->getEndPos().y));

				break;
			}


			// 			CRectangleDisplayObj* shapeDisObj = (CRectangleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 
			// 		
			// 			CRoundRectangleDisplayObj* shapeDisObj = (CRoundRectangleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 
			// 		
			// 			CEllipsDisplayObj* shapeDisObj = (CEllipsDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

		case SHAPE_POLYGON:
			{
				CPolygonDisplayObj* polyDisObj = (CPolygonDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				vector<HPoint> points = polyDisObj->GetAllPoints();
				for (int i = 0; i < points.size(); ++i)
				{
					points[i] = HPoint(points[i].x, - points[i].y );
				}
				polyDisObj->ChangeAllPoints(points);

				break;
			}
		case SHAPE_CURVE:
			{
				CCurveDisplayObj* curveDisObj = (CCurveDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				CCurveObj* curveObj = (CCurveObj*)curveDisObj->GetEntityObj();
				curveObj->SetStartPosY(-curveObj->GetStartPosY());
				curveObj->SetFirPosY(-curveObj->GetFirPosY());
				curveObj->SetSecPosY(-curveObj->GetSecPosY());
				curveObj->SetEndPosY(-curveObj->GetEndPosY());

				break;
			}
			//CImageDisplayObj* shapeDisObj = (CImageDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

			// 		case SHAPE_WORD:
			// 			CWordDisplayObj* shapeDisObj = (CWordDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

			// 		case SHAPE_CURVE:

			// 		case SHAPE_CIRCLE:
			// 			CCircleDisplayObj* shapeDisObj = (CCircleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

			//case SHAPE_POLYLINE:
		default:
			return;
		}
	}
}


void ACAD_EXPORT_TOOL_COMMON_IMPL::Scale_GroundPattern(CGroundPatternDisObj *disObj, double scale_x, double scale_y)
{
	CGroundPatternObj* obj = (CGroundPatternObj*)disObj->GetEntityObj();
	long layerId = disObj->GetLayerId();
	list<CShape*> lstShapes = obj->GetShapeList();
	for (list<CShape*>::iterator iter = lstShapes.begin(); iter!= lstShapes.end(); ++iter)
	{
		eShapeStyle shapeStyle = (*iter)->getShapeStyle();
		switch(shapeStyle)
		{
		case SHAPE_LINE:
			{
				CLineDisplayObj* lineDisObj = (CLineDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				CLineObj* pLineObj = (CLineObj*)lineDisObj->GetEntityObj();
				pLineObj->SetStartPosX(pLineObj->GetStartPosX() * scale_x);
				pLineObj->SetStartPosY(pLineObj->GetStartPosY() * scale_y);
				pLineObj->SetEndPosX(pLineObj->GetEndPosX() * scale_x);
				pLineObj->SetEndPosY(pLineObj->GetEndPosY() * scale_y);
				break;
			}

		case SHAPE_RECTANGLE:
		case SHAPE_ROUND_RECTANGLE:
		case SHAPE_ELLIPSE:
		case SHAPE_IMAGE:
			{
				CShapeDisplayObj* shapeDisObj = dynamic_cast<CShapeDisplayObj*>((*iter)->GetDisplayObjByLayerID(layerId));
				shapeDisObj->setStartPos(HPoint(shapeDisObj->getStartPos().x * scale_x, shapeDisObj->getStartPos().y * scale_y));
				shapeDisObj->setEndPos(HPoint(shapeDisObj->getEndPos().x * scale_x, shapeDisObj->getEndPos().y * scale_y));

				break;
			}
			// 			CRectangleDisplayObj* shapeDisObj = (CRectangleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 
			// 		
			// 			CRoundRectangleDisplayObj* shapeDisObj = (CRoundRectangleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 
			// 		
			// 			CEllipsDisplayObj* shapeDisObj = (CEllipsDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

		case SHAPE_POLYGON:
			{
				CPolygonDisplayObj* polyDisObj = (CPolygonDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				vector<HPoint> points = polyDisObj->GetAllPoints();
				for (int i = 0; i < points.size(); ++i)
				{
					points[i] = HPoint(points[i].x * scale_x, points[i].y * scale_y);
				}
				polyDisObj->ChangeAllPoints(points);

				break;
			}
		case SHAPE_CURVE:
			{
				CCurveDisplayObj* curveDisObj = (CCurveDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
				CCurveObj* curveObj = (CCurveObj*)curveDisObj->GetEntityObj();
				curveObj->SetStartPosX(curveObj->GetStartPosX() * scale_x);
				curveObj->SetStartPosY(curveObj->GetStartPosY() * scale_y);
				curveObj->SetFirPosX(curveObj->GetFirPosX() * scale_x);
				curveObj->SetFirPosY(curveObj->GetFirPosY() * scale_y);
				curveObj->SetSecPosX(curveObj->GetSecPosX() * scale_x);
				curveObj->SetSecPosY(curveObj->GetSecPosY() * scale_y);
				curveObj->SetEndPosX(curveObj->GetEndPosX() * scale_x);
				curveObj->SetEndPosY(curveObj->GetEndPosY() * scale_y);

				break;
			}

			//CImageDisplayObj* shapeDisObj = (CImageDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 		case SHAPE_WORD:
			// 			CWordDisplayObj* shapeDisObj = (CWordDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);
			// 		case SHAPE_CURVE:
			// 		case SHAPE_CIRCLE:
			// 			CCircleDisplayObj* shapeDisObj = (CCircleDisplayObj*)(*iter)->GetDisplayObjByLayerID(layerId);

			//case SHAPE_POLYLINE:
		default:
			return;
		}
	}
}


bool ACAD_EXPORT_TOOL_COMMON_IMPL::IsAutoCadRightState(/*IAcadModelSpace *pModelSpace*/)
{
	bool bRet = true;
	if (!m_pModelSpace)
	{
		bRet = false;
	}
	CLSID clsid;
	CString str;
	//::CoInitialize(NULL);
	HRESULT h = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);
	if(FAILED(h))
	{
		bRet = false;
	}
	else
	{
		IUnknown * pUnknown=NULL;
		h = ::GetActiveObject(clsid, NULL, &pUnknown);//查找是否有AutoCad程序在运行
		if(FAILED(h))
			bRet = false;
	}
	IAcadDocument *pDoc=NULL;
	m_pAcadApp->get_ActiveDocument(&pDoc);
	if (!pDoc)
		bRet = false;
	else
	{
		IAcadLayer *pActiveLayer=NULL;
		pDoc->get_ActiveLayer(&pActiveLayer);
		if (!pActiveLayer)
			bRet = false;
	}
	if (!bRet)
	{
		AfxMessageBox(_T("请勿在导出过程中操作AutoCad，否则将造成导出过程中断！"));
	}
	return bRet;
}


void ACAD_EXPORT_TOOL_COMMON_IMPL::DeleteProgressDlg(CExportProgressDlg* pProgressDlg)
{
	if(pProgressDlg)
	{
		pProgressDlg->CloseWindow();
		pProgressDlg->DestroyWindow();
		delete pProgressDlg;
		pProgressDlg = NULL;
	}
}

#pragma endregion